脚本宝典收集整理的这篇文章主要介绍了微信小程序获得微信头像和昵称,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
{
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; // 打开模态框进行授权
}
}
});
}