在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 小程序啟動報(bào)錯,求一個排查方法

小程序啟動報(bào)錯,求一個排查方法

小程序報(bào)錯

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

在開發(fā)工具上會二次渲染,但是在手機(jī)上就不能了,而且這個報(bào)錯是時有時無的,求大神分享一下報(bào)錯的原因,該如何排查呢

在網(wǎng)上也有人遇見同樣的問題了

解決方案:在app.js中還沒有給globalData賦值時卻提前跳轉(zhuǎn)到了調(diào)用globalData數(shù)據(jù)的頁面,所以導(dǎo)致渲染失敗,個人建議做個引導(dǎo)或加載頁面,給數(shù)據(jù)一個緩沖的過程;

我在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
   }
})

因?yàn)橹熬陀鲆娺^頁面初始化完成之后沒有得到數(shù)據(jù),所以我在首頁設(shè)置的是一個空頁面

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進(jìn)行賦值之外沒有任何取值的操作呀

回答
編輯回答
兔寶寶

等到數(shù)據(jù)賦值成功以后再到渲染頁,現(xiàn)在的賦值還是上次的值,導(dǎo)致渲染失敗

2018年1月26日 20:20