微信小程序使用按钮获取用户信息
<button class="submitBtn" open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">微信登录</button>
open-type="getUserInfo" 获取用户信息,可以从bindgetuserinfo回调中获取到用户信息;
bindgetuserinfo="bindGetUserInfo" 用户点击该按钮时,会返回获取到的用户信息,想要触发bindgetuserinfo事件要先给button标签添加open-type类型;
bindGetUserInfo(e){
const that=this;
// 查看是否授权
wx.getSetting({
success(res) {
if (res.authSetting[‘scope.userInfo‘]) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success(res) {
console.log(res)
}
})
}else{
console.log("拒绝")
}
}
})
},
原文:https://www.cnblogs.com/banyuege/p/13256059.html