将wx.switchTab或者其他跳转事件写在onlaunch的代码:
onLaunch: function() {
// 读取登录状态跳转
var that= this;
wx.getStorage({
key: 'userLoginInfo',
success: function (res) {
if (res.data) {
that.data.userLoginData = res.data
wx.switchTab({
url: '../personal/personal',
})
}
},
})
},
这样写的话前几次是可以生效的,但是如果多次编译会报错如下:
解决方法:
将代码写在登录页面的js里的onload内即可,如下:
onLoad: function(options) {
// 读取登录状态跳转
wx.getStorage({
key: 'userLoginInfo',
success: function (res) {
if (res.data) {
app.data.userLoginData = res.data
wx.switchTab({
url: '../personal/personal',
})
}
},
})
},
新手上路,请多指教