小程序报错
Expected updated data but get first rendering data;Expected updated data but get first rendering data
Error: Expected updated data but get first rendering data
在开发工具上会二次渲染,但是在手机上就不能了,而且这个报错是时有时无的,求大神分享一下报错的原因,该如何排查呢
在网上也有人遇见同样的问题了
解决方案:在app.js中还没有给globalData赋值时却提前跳转到了调用globalData数据的页面,所以导致渲染失败,个人建议做个引导或加载页面,给数据一个缓冲的过程;
我在App.js里的代码
App({
onLaunch: function () {
this .getOpenid().then(()=>{
return that.setAdmin()
})
},
getOpenid: function () {
var that = this
return new Promise( function (resolve, reject) {
wx.getStorage({
key: 'openid' ,
success: function (res) {
that.globalData.openId = res.data
return resolve( 'app.js login success' )
},
fail: function () {
wx.login({
success: res => {
var code = res.code; //返回code
var appId =
var secret =
wx.request({
url: 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appId + '&secret=' + secret + '&js_code=' + code + '&grant_type=authorization_code' ,
data: {},
header: {
'content-type' : 'json'
},
success: function (res) {
wx.setStorage({
key: "openid" ,
data: res.data.openid
})
that.globalData.openId = res.data.openid
return resolve( 'app.js login success' )
}
})
}
})
}
})
})
},
setAdmin: function () {
var that = this
return new Promise( function (resolve, reject) {
wx.request({
url: 'http://132.232.22.140:8889/api/club/adminComfirm' ,
method: 'post' ,
data:{
id:that.globalData.openId
},
header:{
"content-type" : 'application/json'
},
success: function (res){
if (res.data.code ==300){
wx.reLaunch({
url: '../../pages/findpage/index' ,
})
}
if (res.data.code == 200){
that.globalData.myclub = res.data.clubnumber
that.globalData.myname = res.data.name
that.globalData.adminOn = true
wx.reLaunch({
url: '../../pages/index/index' ,
})
}
}
})
})
},
globalData: {
userInfo: null ,
openId: null ,
myclub: null ,
myname: null ,
adminOn: false ,
findClub: null ,
findClubNumber: null
}
})
因为之前就遇见过页面初始化完成之后没有得到数据,所以我在首页设置的是一个空页面
app.json
"pages" : [
"pages/midware/index" ,
"pages/index/index" ,
"pages/findpage/index" ,
"pages/signup/index" ,
"pages/join/index" ,
"pages/option/index" ,
"pages/details/index" ,
"pages/setting/index" ,
"pages/memo/index"
],
第一个就是空页面,然后主页面的选择在上面App.js里面来判断的,按道理来说,在页面初始化过程中除了对globalData进行赋值之外没有任何取值的操作呀
等到数据赋值成功以后再到渲染页,现在的赋值还是上次的值,导致渲染失败