无法获取用户头像等信息
<!-- 如果只是展示用户头像昵称,可以使用 <open-data /> 组件 --><open-data type="userAvatarUrl"></open-data><open-data type="userNickName"></open-data><!-- 需要使用 button 来授权登录 --><button open-type="getUserInfo" bindgetuserinfo="bindGetUserInfo">授权登录</button> |
//index.js//获取应用实例const app = getApp()Page({ data: { motto: 'Hello World', userInfo: {}, hasUserInfo: false, canIUse: wx.canIUse('button.open-type.getUserInfo') }, onLoad: function () { // 查看是否授权 wx.getSetting({ success(res) { if (res.authSetting['scope.userInfo']) { // 已经授权,可以直接调用 getUserInfo 获取头像昵称 wx.getUserInfo({ success: function (res) { console.log(res.userInfo) var str = JSON.stringify(res.userInfo); app.alertHui(str, function () { //回调弹窗 }) } }) } } }) }, bindGetUserInfo: function (e) { console.log(e) app.globalData.userInfo = e.detail.userInfo; var str = JSON.stringify(e.detail.userInfo) app.alertHui(str, function () { //回调弹窗 }) }}) |
- 当前 Bug 的表现(可附上截图)
-
预期表现
-
复现路径
-
提供一个最简复现 Demo
