uni-app 表单及表单组件
表单:用于数据的收集和数据的提交
官网地址:https://uniapp.dcloud.io/component/
1.button组件
属性说明
属性名 | 类型 | 默认值 | 说明 | 生效时机 | 平台差异说明 |
---|---|---|---|---|---|
size | String | default | 按钮的大小 | ||
type | String | default | 按钮的样式类型 | ||
plain | Boolean | false | 按钮是否镂空,背景色透明 | ||
disabled | Boolean | false | 是否禁用 | ||
loading | Boolean | false | 名称前是否带 loading 图标 | App-nvue 平台,在 ios 上为雪花,Android上为圆圈 | |
form-type | String | 用于 <form> 组件,点击分别会触发 <form> 组件的 submit/reset 事件 |
|||
open-type | String | 开放能力 | |||
hover-class | String | button-hover | 指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果 | App-nvue 平台暂不支持 | |
hover-start-time | Number | 20 | 按住后多久出现点击态,单位毫秒 | ||
hover-stay-time | Number | 70 | 手指松开后点击态保留时间,单位毫秒 | ||
app-parameter | String | 打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效 | 微信小程序、QQ小程序 | ||
hover-stop-propagation | boolean | false | 指定是否阻止本节点的祖先节点出现点击态 | 微信小程序 | |
lang | string | 'en' | 指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。 | 微信小程序 | |
session-from | string | 会话来源,open-type="contact"时有效 | 微信小程序 | ||
send-message-title | string | 当前标题 | 会话内消息卡片标题,open-type="contact"时有效 | 微信小程序 | |
send-message-path | string | 当前分享路径 | 会话内消息卡片点击跳转小程序路径,open-type="contact"时有效 | 微信小程序 | |
send-message-img | string | 截图 | 会话内消息卡片图片,open-type="contact"时有效 | 微信小程序 | |
show-message-card | boolean | false | 是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效 | 微信小程序 | |
@getphonenumber | Handler | 获取用户手机号回调 | open-type="getPhoneNumber" | 微信小程序 | |
@getuserinfo | Handler | 用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo | open-type="getUserInfo" | 微信小程序 | |
@error | Handler | 当使用开放能力时,发生错误的回调 | open-type="launchApp" | 微信小程序 | |
@opensetting | Handler | 在打开授权设置页并关闭后回调 | open-type="openSetting" | 微信小程序 | |
@launchapp | Handler | 从小程序打开 App 成功的回调 | open-type="launchApp" | 微信小程序 |
<template> <view> <view class="uni-padding-wrap uni-common-mt"> <button type="primary">页面主操作 Normal</button> <button type="primary" loading="true">页面主操作 Loading</button> <button type="primary" disabled="true">页面主操作 Disabled</button> <button type="default">页面次要操作 Normal</button> <button type="default" disabled="true">页面次要操作 Disabled</button> <button type="warn">警告类操作 Normal</button> <button type="warn" disabled="true">警告类操作 Disabled</button> <view class="button-sp-area"> <button type="primary" plain="true">按钮</button> <button type="primary" disabled="true" plain="true">不可点击的按钮</button> <button type="default" plain="true">按钮</button> <button type="default" disabled="true" plain="true">按钮</button> <button class="mini-btn" type="primary" size="mini">按钮</button> <button class="mini-btn" type="default" size="mini">按钮</button> <button class="mini-btn" type="warn" size="mini">按钮</button> </view> </view> </view> </template> <script> var _self; export default { data() { return { } } } </script> <style> </style>
2.checkbox:多项选择器,内部由多个checkbox组成。
属性说明
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
value | String | <checkbox> 标识,选中时触发 <checkbox-group> 的 change 事件,并携带 <checkbox> 的 value。 |
|
disabled | Boolean | false | 是否禁用 |
checked | Boolean | false | 当前是否选中,可用来设置默认选中 |
color | Color | checkbox的颜色,同css的color |
<template> <view> <view class="uni-padding-wrap uni-common-mt"> <view class="uni-title uni-common-mt">默认样式</view> <view> <checkbox-group> <label> <checkbox value="cb" checked="true" />选中 </label> <label> <checkbox value="cb" />未选中 </label> </checkbox-group> </view> <view class="uni-title uni-common-mt">不同颜色和尺寸的checkbox</view> <view> <checkbox-group> <label> <checkbox value="cb" checked="true" color="#FFCC33" style="transform:scale(0.7)" />选中 </label> <label> <checkbox value="cb" color="#FFCC33" style="transform:scale(0.7)" />未选中 </label> </checkbox-group> </view> </view> <view class="uni-padding-wrap"> <view class="uni-title uni-common-mt"> 推荐展示样式 <text>\n使用 uni-list 布局</text> </view> </view> <view class="uni-list"> <checkbox-group @change="checkboxChange"> <label class="uni-list-cell uni-list-cell-pd" v-for="item in items" :key="item.value"> <view> <checkbox :value="item.value" :checked="item.checked" /> </view> <view>{{item.name}}</view> </label> </checkbox-group> </view> </view> </template> <script> export default { data() { return { title: 'checkbox 复选框', items: [{ value: 'USA', name: '美国' }, { value: 'CHN', name: '中国', checked: 'true' }, { value: 'BRA', name: '巴西' }, { value: 'JPN', name: '日本' }, { value: 'ENG', name: '英国' }, { value: 'FRA', name: '法国' } ] } }, methods: { checkboxChange: function (e) { var items = this.items, values = e.detail.value; for (var i = 0, lenI = items.length; i < lenI; ++i) { const item = items[i] if(values.includes(item.value)){ this.$set(item,'checked',true) }else{ this.$set(item,'checked',false) } } } } } </script> <style> .uni-list-cell { justify-content: flex-start } </style>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!