微信小程序授权
<button open-type="getUserInfo" bindgetuserinfo="getAuthorization"> 授权 </button> // 授权 getAuthorization(){ let that = this let code = wx.login() // 查看是否授权 wx.getSetting({ success: function (res) { console.log(res) if (res.authSetting[‘scope.userInfo‘]) { console.log(res.authSetting[‘scope.userInfo‘]) // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { let userInfo = JSON.parse(res.rawData) that.setData({ username: userInfo.nickName, userImg: userInfo.avatarUrl }) } }) }else { console.log("未授权=====") wx.authorize({ scope: ‘scope.userInfo‘, success(res) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { let userInfo = JSON.parse(res.rawData) that.setData({ username: userInfo.nickName, userImg: userInfo.avatarUrl }) } }) }, fail(res){ console.log(res) } }) } } }) },
相关推荐
kgshuo 2020-09-25
Tomato 2020-09-10
taiyangyu 2020-09-10
CodeAndroid 2020-09-10
small 2020-07-29
sucheng 2020-07-26
zuoliangzhu 2020-07-20
CodeAndroid 2020-07-14
xiaoxubbs 2020-07-04
sucheng 2020-06-25
kgshuo 2020-06-14
意外金喜 2020-06-14
zuoliangzhu 2020-06-14
tianping 2020-06-14
hgzhang 2020-06-14
killgod 2020-06-14
戴翔的技术 2020-06-14
郴州小程序 2020-06-13