<u-button :loading="loading" :disabled="loading" :custom-style="customStyle" class="quick-btn wx-quick" open-type="getPhoneNumber" @getphonenumber="bindPhone"></u-button>
按照官方文写的获取不到,uni.getUserInfo
下面都不执行
官方文档 https://uniapp.dcloud.io/api/...
###我一直是这么写的,你可以参考
html
<u-button type="primary" open-type="getUserInfo" size="medium" @getuserinfo="mpGetUserInfo">微信授权一键登录</u-button>
js
mpGetUserInfo(result) {
console.log('mpGetUserInfo', result);
if (result.detail.errMsg !== 'getUserInfo:ok') {
this.$refs.uToast.show({
title: '授权体验更友好',
type: 'warning',
})
return;
}
this.$refs.uToast.show({
title: '授权成功',
type: 'success',
})
this.login()
},
login() {
uni.login({
provider: 'weixin',
success: () => {
this.getUserInfo()
}
});
},
// 获取用户信息 API 在小程序可直接使用,在 5+App 里面需要先登录才能调用
getUserInfo() {
uni.getUserInfo({
provider: 'weixin',
success: (result) => {
console.log(result);
}
});
},