Mini Program started to report an error and asked for a troubleshooting method.

Mini Program reported an error

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

it will be rendered twice on the development tool, but not on the mobile phone, and this error report is occasional. Ask God to share the reasons for the error report, how to troubleshoot it

some people have encountered the same problem on the Internet

solution: before you assign a value to globalData in app.js, you jump to the page that calls globalData data in advance, resulting in rendering failure. You are recommended to boot or load the page to give the data a buffering process.

my code in 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
   }
})

because I have met before that I did not get the data after the page initialization was completed, so I set up an empty page on the home page

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"
     ],

the first one is an empty page, and then the choice of the main page is judged in the above App.js. According to reason, there is no operation to take a value except to assign a value to globalData in the process of page initialization


wait until the data assignment is successful before going to the rendering page. The current assignment is the same as the last one, resulting in rendering failure

Menu