Cannot read property 'nickName' of 错误
查看运维中心的错误列表, 发现这个错误,
看起来应该是 调用wx.createUserInfoButton接口之后的onTap回调中 res.userInfo中的nickName是undefined,
请问一下 什么情况下会导致nickName为空呢? 我这里已经先先判断了userInfo为空的情况的.
Cannot read property ‘nickName’ of undefined;at tap callback function
贴代码
var button = wx.createUserInfoButton({
type: "text",
text: "微信登陆",
image: "",
style: {
left: x,
top: y,
width: 150,
height: 48,
lineHeight: 48,
backgroundColor: "#09bb07",
color: "#ffffff",
textAlign: "center",
fontSize: 22,
borderRadius: 24
}
});
button.onTap((res) => {
console.log("用户授权:", res);
if(res.userInfo) {
WindowManage.showMiniLoding();
UserInfo.GetInstance().init(res.userInfo);
button.destroy();
callBack()
}
});
init (userInfo) {
this.nickName = userInfo.nickName
this.avatarUrl = userInfo.avatarUrl
this.gender = userInfo.gender //性别 0:未知、1:男、2:女
// .......
}