我在使用wx.getStorage来获取缓存的数据并使用 this.setDate 来进行赋值时报错
Cannot read property ‘setData’ of undefined
无法读取未定义的属性“setData”
问题代码
wx.getStorage({
key: 'user_Data',
success(res) {
if(res.data != null && res.data !=0){
this.setData({
userInfo: res.data,
hasUserInfo: true,
canIUseGetUserProfile:false,
wx_login: false
})
}
}
})
},
解决方法
将 success(res) {} 改成 success: res => {} 就可以了
wx.getStorage({
key: 'user_Data',
success: res => {
if(res.data != null && res.data !=0){
this.setData({
userInfo: res.data,
hasUserInfo: true,
canIUseGetUserProfile:false,
wx_login: false
})
}
}
})
},