handleUserProfile1(e) {
console.log('当前基础库版本:', wx.getSystemInfoSync().SDKVersion);
console.log(e)
if (e.detail.errMsg.includes('deny')) {
wx.showModal({
title: '提示',
content: '需要授权才能继续操作',
success: (res) => {
if (res.confirm) wx.openSetting()
}
})
}
else if (e.detail.errMsg === 'getUserProfile:ok') {
const { avatarUrl, nickName } = e.detail.userInfo
this.setData({ avatar: avatarUrl }) // 更新头像显示
} else {
console.error('授权失败:', e.detail.errMsg)
}
},
<button class="username"
open-type="getUserProfile"
bind:getuserprofile="handleUserProfile1"
type="default"
>获取信息</button>
可能是需要隐私协议授权,可以了解一下
https://developers.weixin.qq.com/miniprogram/dev/framework/user-privacy/PrivacyAuthorize.html