{errMsg: "getUserInfo:ok", rawData: "{"nickName":"We1.","gender":1,"language":"zh_CN","…guItElHFicHRIOxsPXGG1QYIbr6JaBtgfevMEiczXVQ/132"}", userInfo: {…}, signature: "1d1fe7f5588399a9aca0a6dbb9941540701e68f4", encryptedData: "VQfGahUPnAfw1S5X7IqL51WHQaneuO78WaxDN3MMonyTI3kDQV…50gNguUzSHhmt/saaVabDwj9+yal1BNmkNJraFiGadjtjsV4c", …}encryptedData: "VQfGahUPnAfw1S5X7IqL51WHQaneuO78WaxDN3MMonyTI3kDQVMPp7L4T+1kFHdZTDv0kUejLcA7zyHd6tNF+ECoifcYvRKPSll2xU7jTWHm5HxePpNo2A1TdIL4FWGFOI52btjr9RnL0pvEPUv4Ty/JcwvSFmrwUZCNCUAfa5GDX3nJK51hJO8Fhlqdl1rndak3lLhf8gsnFvM0aALRtKb883M4k3SqjOEbeNWYd+1BG9jZ5kzhXhL0GSj1DB7LzLDgftQFqo2QKvC38kxF+luEDJ0QBWy7MC29Qp8vujZV4uzjhyFDdIamFsPxyc9ReaV2H2hNDJwknPXVamwALHKi5IhLXy6Fglj9pRuLzR0zS9FLjSDJAuxf/QCxYvnNLGD80rHh4Eew+lmdDLdI7w6PwkaxGol3Q12Jt1DSPOHMUAH7T1YA6/8IDYFhjLnONOyfm0DBOddQXtz50gNguUzSHhmt/saaVabDwj9+yal1BNmkNJraFiGadjtjsV4c"errMsg: "getUserInfo:ok"iv: "0ve/BCw0smvjp5AvqPGPqg=="rawData: "{"nickName":"We1.","gender":1,"language":"zh_CN","city":"Mudanjiang","province":"Heilongjiang","country":"China","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/DYAIOgq83eqiahgLmCiapFLIp3U0137iaicEwmAVyvBmVvkib6guItElHFicHRIOxsPXGG1QYIbr6JaBtgfevMEiczXVQ/132"}"signature: "1d1fe7f5588399a9aca0a6dbb9941540701e68f4"userInfo: {nickName: "We1.", gender: 1, language: "zh_CN", city: "Mudanjiang", province: "Heilongjiang", …}__proto__: Object
如果你原来用getUserInfo获取openid且同时保存用户信息的,建议你改用auth.code2Session和getUserProfile,不然会出现两个弹窗体验不好。如果只是用于获取用户信息的就直接改用getUserProfile,用getUserProfile时在bindtap调用的方法里面调用接口即可
怎么救?
https://developers.weixin.qq.com/community/develop/doc/000cacfa20ce88df04cb468bc52801?blockType=1
<image wx:if='{{userInfo.avatarUrl}}' class="avatarUrl" src="{{userInfo.avatarUrl}}"></image>
<button wx:else bindgetuserinfo='handleGetUserInfo' open-type="getUserInfo">获取用户信息</button>
<text class="userName">{{userInfo.nickName}}</text>
<!-- 测试事件绑定 -->
<!-- <view class="goStudy" catchtap="handleParent">
<text catchtap='handleChild'>hello world</text>
</view> -->
<view class="goStudy" catchtap="toLogs">
<text >hello world</text>
</view>
</view>
额。。。所以你想问什么问题
<image wx:if='{{userInfo.avatarUrl}}' class="avatarUrl" src="{{userInfo.avatarUrl}}"></image>
<button wx:else bindgetuserinfo='handleGetUserInfo' open-type="getUserProfile">获取用户信息</button>
<text class="userName">{{userInfo.nickName}}</text>
<!-- 测试事件绑定 -->
<!-- <view class="goStudy" catchtap="handleParent">
<text catchtap='handleChild'>hello world</text>
</view> -->
<view class="goStudy" catchtap="toLogs">
<text >hello world</text>
</view>
Page({
/**
* 页面的初始数据
*/
data: {
msg: '初始化测试数据',
userInfo: {}, // 用户的基本信息
},
handleParent() {
console.log('parent')
},
handleChild() {
console.log('child')
},
// 跳转至logs页面的方法
toLogs() {
wx.navigateTo({
url: '/pages/logs/logs',
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log('onLoad() 监听页面加载');
// debugger;
// 修改msg的状态数据, 语法: this.setData
// console.log(this.data.msg) // this代表当前页面的实例对象
// setTimeout(() => {
// this.setData({
// msg: '修改之后的数据'
// })
// console.log(this.data.msg)
// }, 2000)
// 授权以后获取用户信息
wx.getUserProfile({
success: (res) => {
console.log(res);
this.setData({
userInfo: res.userInfo
})
},
fail: (err) => {
console.log(err);
}
})
},
// 获取用户信息的回调
handleGetUserInfo(res) {
console.log(res)
if (res.detail.userInfo) {// 允许
// 修改userInfo的状态数据
this.setData({
userInfo: res.detail.userInfo
})
}
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
console.log('onReady() 监听页面初次渲染完成');
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
console.log('onShow() 监听页面显示 执行多次');
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
console.log('onHide() 监听页面隐藏');
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
console.log('onUnload() 监听页面卸载');
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})