button.md 6.7 KB
Newer Older
M
mehaotian 已提交
1 2 3 4 5 6 7 8 9 10 11 12
#### button

按钮。

**属性说明**

|属性名|类型|默认值|说明|生效时机|平台差异说明|
|:-|:-|:-|:-|:-|:-|
|size|String|default|按钮的大小|||
|type|String|default|按钮的样式类型|||
|plain|Boolean|false|按钮是否镂空,背景色透明|||
|disabled|Boolean|false|是否禁用|||
d-u-a's avatar
d-u-a 已提交
13
|loading|Boolean|false|名称前是否带 loading 图标||App-nvue 平台,在 ios 上为雪花,Android上为圆圈|
M
mehaotian 已提交
14 15
|form-type|String||用于 ``<form>`` 组件,点击分别会触发 ``<form>`` 组件的 submit/reset 事件|||
|open-type|String||开放能力|||
d-u-a's avatar
d-u-a 已提交
16
|hover-class|String|button-hover|指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果||App-nvue 平台暂不支持|
M
mehaotian 已提交
17
|hover-start-time|Number|20|按住后多久出现点击态,单位毫秒|||
W
wanganxp 已提交
18
|hover-stay-time|Number|70|手指松开后点击态保留时间,单位毫秒|||
d-u-a's avatar
d-u-a 已提交
19
|app-parameter|String||打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效||微信小程序、QQ小程序|
20 21 22 23 24 25
|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"时有效||微信小程序|
d-u-a's avatar
d-u-a 已提交
26
|show-message-card|boolean|false|是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效||微信小程序|
W
wangyaqi 已提交
27
|@getphonenumber|Handler||获取用户手机号回调|open-type="getPhoneNumber"|微信小程序|
W
wanganxp 已提交
28 29 30
|@getuserinfo|Handler||用户点击该按钮时,会返回获取到的用户信息,从返回参数的detail中获取到的值同uni.getUserInfo|open-type="getUserInfo"|微信小程序|
|@error|Handler||当使用开放能力时,发生错误的回调|open-type="launchApp"|微信小程序|
|@opensetting|Handler||在打开授权设置页并关闭后回调|open-type="openSetting"|微信小程序|
W
wangyaqi 已提交
31 32
|@launchapp|Handler||打开 APP 成功的回调|open-type="launchApp"|微信小程序|

W
wanganxp 已提交
33
- **注1:``button-hover`` 默认为 ``{background-color: rgba(0, 0, 0, 0.1); opacity: 0.7;}``**
W
wangyaqi 已提交
34
- ```open-type="launchApp"```时需要调起的APP接入微信OpenSDK[详见](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html)
M
mehaotian 已提交
35 36 37 38 39 40 41 42 43 44 45 46
 
**size 有效值**

|值|说明|
|:-|:-|
|default|默认大小|
|mini|小尺寸|

**type 有效值**

|值|说明|
|:-|:-|
47
|primary|微信小程序为绿色,App、H5、百度小程序、支付宝小程序为蓝色,字节跳动小程序为红色,QQ小程序为浅蓝色|
M
mehaotian 已提交
48 49 50 51 52 53 54 55 56 57 58 59 60 61
|default|白色|
|warn|红色|

**form-type 有效值**

|值|说明|
|:-|:-|
|submit|提交表单|
|reset|重置表单|

**open-type 有效值**

|值|说明|平台差异说明|
|:-|:-|:-|
W
wanganxp 已提交
62
|feedback|打开“意见反馈”页面,用户可提交反馈内容并上传日志|App、微信小程序、QQ小程序|
63
|share|触发用户转发|微信小程序、百度小程序、支付宝小程序、字节跳动小程序、QQ小程序|
G
Granzon 已提交
64
|getUserInfo|获取用户信息,可以从@getuserinfo回调中获取到用户信息,包括头像、昵称等信息|微信小程序、百度小程序、QQ小程序|
W
wanganxp 已提交
65
|contact | 打开客服会话,如果用户在会话中点击消息卡片后返回应用,可以从 @contact 回调中获得具体信息 |微信小程序、百度小程序|
66
|getPhoneNumber | 获取用户手机号,可以从@getphonenumber回调中获取到用户信息|微信小程序、百度小程序、字节跳动小程序 |
W
wanganxp 已提交
67 68 69 70 71 72
|launchApp | 打开APP,可以通过app-parameter属性设定向APP传的参数|[微信小程序](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/launchApp.html)[QQ小程序](https://q.qq.com/wiki/develop/miniprogram/frame/open_ability/open_app.html)|
|openSetting | 打开授权设置页 |微信小程序、百度小程序|
|getAuthorize | 支持小程序授权 | 支付宝小程序 |
|contactShare | 分享到通讯录好友 | 支付宝小程序 |
|lifestyle | 关注生活号 | 支付宝小程序 |
|openGroupProfile|呼起QQ群资料卡页面,可以通过group-id属性设定需要打开的群资料卡的群号,同时manifest中必须配置groupIdList|QQ小程序基础库1.4.7版本+|
M
mehaotian 已提交
73 74

**注意** 
W
wanganxp 已提交
75
- 在小程序中,开发者可以登录 [微信小程序管理后台](https://mp.weixin.qq.com/)[QQ小程序后台](https://q.qq.com/#/)后,进入菜单“客服反馈”页面获取反馈内容。
M
mehaotian 已提交
76 77
- 在 App 中,开发者登录 [DCloud开发者中心](https://dev.dcloud.net.cn/) 后点击应用名称,进入左侧菜单“用户反馈”页面获取反馈内容。
- 点击 share 分享按钮时会触发 [onShareAppMessage](/api/plugins/share)
hbcui1984's avatar
hbcui1984 已提交
78
- 支付宝小程序平台,获取用户手机号时,建议先通过条件编译的方式,调用支付宝原生API,[参考](https://docs.alipay.com/mini/api/getphonenumber)
M
mehaotian 已提交
79 80


W
wangyaqi 已提交
81
**示例** [查看演示](https://uniapp.dcloud.io/h5/pages/component/button/button)
M
mehaotian 已提交
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108

```html
<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>
```

![uniapp](https://img-cdn-qiniu.dcloud.net.cn/uniapp/doc/img/button.png?t=201857)