微信小程序登录功能(获取头像昵称openID)信息,输出结果:
js方法
//授权方法
login: function () {
wx.showModal({
title: '提示',
content: '您第一次使用需要授权头像昵称',
success: function (sm) {
if (sm.confirm) {
wx.getUserProfile({
desc: '获取你的昵称、头像',
success: res => {
console.log(res.userInfo) //控制台输出结果
console.log("获取成功");
var tx = res.userInfo.avatarUrl
var name = res.userInfo.nickName
console.log(tx)
console.log(name)
wx.showToast({
title: '登录成功',
icon: 'success',
duration: 2000
});
},
fail: res => {
console.log(res)
//拒绝授权
wx.showToast({
title: '登录失败',
icon: 'error',
duration: 2000
});
return;
}
});
} else {
console.log("取消授权")
}
}
})
},