{
wx.getSetting({
success: res => {
if (res.authSetting && res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success: function (data) {
console.log(data.userInfo);
// {
// avatarUrl: '微信头像img文件path'
// nickname: '微信昵称'
// }
}
});
} else {
this.showShouquan = true; // 打开模态框进行授权
}
}
});
}
微信授权
xxxxxxx小程序将获得您的微信头像、昵称等公开消息
getUserInfoFromWx (e) {
this.$store.state.user_userinfo = e.mp.detail.userInfo;
this.showShouquan = false;
},
cancelShouquan () {
this.showShouquan = false;
},