解决新版微信小程序开发getUserInfo获取不到信息
解决新版微信小程序开发getUserInfo获取不到信息
【声明本人菜鸡,如有不足请大神指点】
请参考文档:
https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801


文档里面已经说明wx.getUserInfo接口的返回参数不变,但开发者获取的userInfo为匿名信息, 获取到的只能是匿名信息 获取不到用户授权信息
我的解决办法是把getUserInfo改为getUserProfile:
<image wx:if="{{userInfo.avatarUrl}}" class="avatarUrl" src="{{userInfo.avatarUrl}}"></image><button wx:if="{{canIUseGetUserProfile}}" bindtap="getUserProfile"> 获取授权信息 </button><text class="username" wx:if="{{userInfo.nickName}}">{{userInfo.nickName}}</text>
在js内定义getUserProfile方法:
data: {msg:'初始化数据',userInfo:{}, // 用户基本信息canIUseGetUserProfile: false,},// 获取用户信息回调getUserProfile(e) {wx.getUserProfile({desc: '音乐', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写success: (res) => {console.log(res)this.setData({userInfo: res.userInfo,hasUserInfo: true,canIUseGetUserProfile:false})},fail:(error) => {console.log(error)}})},
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
