全局变量在app端没有作用,在网页端正常生效

ui.request({
url: `${ui.getApp().globalData.server}/api/user/login`,
data:{
account:this.usernameval,
password:this.passwordval
},
header: headerValue,
success: function (res) {
if(res.data.code == 0){
ui.showToast({ title: res.data.msg })
ui.getApp().globalData.isLogin = false;
} else {
ui.getApp().globalData.isLogin = true;
ui.showToast({ title: res.data.msg, icon:"success" })
ui.getApp().globalData.token = res.data.data.userinfo.token;
console.log(res.data.data.userinfo)
ui.navigateTo({
url: `/pages/user?userinfo=${res.data.data.userinfo}`
})
}
},
fail: function (e) {
console.log(e)
}
 
这是在login页面写的ajax 把获取到的userinfo以及isLogin存到全局变量里,
然后在用户页面刷新
if(ui.getApp().globalData.isLogin == true){
var that = this;
ui.getApp().globalData.header.token = ui.getApp().globalData.token;
ui.request({
url:`${ui.getApp().globalData.server}/api/user/index`,
header:ui.getApp().globalData.header,
success:function(res) {
that.isLogin = true;
that.userinfo = res.data.data.userinfo;
that.userbio = res.data.data.userinfo.bio;
ui.getApp().globalData.userinfo = res.data.data.userinfo;
that.username = that.userinfo.username;
that.portraitUrl = `${ui.getApp().globalData.server}${that.userinfo.avatar}`
},
fail:function(e) {
that.isLogin = false;
}
})
}
 
但是在网页端都是能获取到值的,手机端全部变成了undefined
已邀请:

要回复问题请先登录注册



QQ:378966107

邮箱:frank@uileader.com

微信进交流群 加小助手微信进交流群