十四.按钮 button

button

按钮

属性类型默认值必填说明
sizestringdefault按钮的大小,default/mini(小尺寸)
typestringdefault按钮的样式类型, primary(原色)/default(默认/warn(警告)
plainbooleanfalse按钮是否镂空,背景色透明
disabledbooleanfalse是否禁用
loadingbooleanfalse名称前是否带 loading 图标
form-typestring用于 form 组件,点击分别会触发 form 组件的 submit/reset 事件
open-typestring微信开放能力
hover-classstringbutton-hover指定按钮按下去的样式类。当 hover-class="none" 时,没有点击态效果
hover-stop-propagationbooleanfalse指定是否阻止本节点的祖先节点出现点击态
hover-start-timenumber20按住后多久出现点击态,单位毫秒
hover-stay-timenumber70手指松开后点击态保留时间,单位毫秒
langstringen指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。
session-fromstring会话来源,open-type="contact"时有效
send-message-titlestring当前标题会话内消息卡片标题,open-type="contact"时有效
send-message-pathstring当前分享路径会话内消息卡片点击跳转小程序路径,open-type="contact"时有效
send-message-imgstring截图会话内消息卡片图片,open-type="contact"时有效
app-parameterstring打开 APP 时,向 APP 传递的参数,open-type=launchApp时有效
show-message-cardbooleanfalse是否显示会话内消息卡片,设置此参数为 true,用户进入客服会话会在右下角显示"可能要发送的小程序"提示,用户点击后可以快速发送小程序消息,open-type="contact"时有效
bindgetuserinfoeventhandle用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致,open-type="getUserInfo"时有效
bindcontacteventhandle客服消息回调,open-type="contact"时有效
bindgetphonenumbereventhandle获取用户手机号回调,open-type=getPhoneNumber时有效
binderroreventhandle当使用开放能力时,发生错误的回调,open-type=launchApp时有效
bindopensettingeventhandle在打开授权设置页后回调,open-type=openSetting时有效
bindlaunchappeventhandle打开 APP 成功的回调,open-type=launchApp时有效

open-type的合法值

说明
contact打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息
share触发用户转发. 不能将程序转发到朋友圈
getPhoneNumber获取用户手机号,可以从bindgetphonenumber回调中获取到用户信息. 不是企业的小程序号, 是没有权限获取用户号码.
getUserInfo获取用户信息,可以从bindgetuserinfo回调中获取到用户信息
launchApp打开APP,可以通过app-parameter属性设定向APP传的参数
openSetting打开授权设置页
feedback打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容

getPhoneNumber

  1. 绑定事件bindgetPhoneNumber
  2. 在事件的回调函数中, 通过参数来获取信息
  3. 获取到的信息已经加密过了, 需要用户自己搭建小程序的后台服务器. 来后台服务器中进行解析手机号, 返回小程序中就可以看到信息了

getUserInfo

getUserInfo的用法和getphoneNumber类似, 但是信息不会加密

launchApp

在小程序中直接打开APP

  1. 需要先在小程序app中,通过app的某个链接打开小程序
  2. 在小程序中再通过这个功能重新打开app

例: 用户上传图片

<button bindtap='handleChooseAlbun'>选中图片</button>
Page({
	data:{
		imagePata: ''
	},
	handleChooseAlbun(){
		//系统API, 让用户在相册中选择图片(或者拍照)
		wx:chooseImage({
			success: (res)=>{
			//取出路径
			const path = res.tempFilePaths[0]
			//设置imagePath
			this.setData({
				imagePath:path
			})
			}
		})
	}
})
<!-- 
<button class="default" size="default" type="default" plain="default" disabled="false" loading="false"
  hover-class="button-hover" hover-stop-propagation="false"
   form-type="submit|reset" open-type="contact|share|getUserInfo|openSetting|feedback" >
  
</button> 
-->
<button size="default" type="primary" >原色按钮1</button>
<button size="default" type="default" >默认按钮2</button>
<button size="default" type="warn" >警告按钮3</button>
<button size="default" type="dispabled" >禁用按钮4</button>
<button size="default" loading >loading按钮5</button>
<!--
contact	打开客服会话,如果用户在会话中点击消息卡片后返回小程序,可以从 bindcontact 回调中获得具体信息
share	触发用户转发,使用前建议先阅读使用指引	
getPhoneNumber	获取用户手机号,可以从bindgetphonenumber回调中获取到用户信息,具体说明	
getUserInfo	获取用户信息,可以从bindgetuserinfo回调中获取到用户信息	
launchApp	打开APP,可以通过app-parameter属性设定向APP传的参数具体说明	
openSetting	打开授权设置页	
feedback	打开“意见反馈”页面,用户可提交反馈内容并上传日志,开发者可以登录小程序管理后台后进入左侧菜单“客服反馈”页面获取到反馈内容
-->  
<button open-type="contact">contact</button>
<button open-type="share">share</button>
<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber">getPhoneNumber</button>
<button open-type="getUserInfo" bindgetuserinfo="getUserInfo">getUserInfo</button>
<button open-type="launchApp">launchApp</button>
<button open-type="openSetting">openSetting</button>
<button open-type="feedback">feedback</button>
Page({
  data: {

  },
  getPhoneNumber (e) {
    console.log(e);
  },
  getUserInfo (e) {
    console.log(e);
  }
})
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值