boolean wx.canIUse(string schema)
基础库 1.1.1 开始支持,低版本需做兼容处理。
判断小程序的API,回调,参数,组件等是否在当前版本可用。
获取用户信息
0.判断授权button是否可用
data: {
canIUse: wx.canIUse('button.open-type.getUserInfo')
},
1.判断用户是否已经授权过,
wx.getSetting({
success(res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success(res) {
console.log(res.userInfo)
}
})
}
}
})
2.没有授权,发起授权请求
<button
wx:if="{{canIUse}}"
open-type="getUserInfo"
bindgetuserinfo="bindGetUserInfo"
>
bindGetUserInfo(e) {
console.log(e.detail.userInfo)
}
网友评论