收藏
回答

报错 Error: Expected updated data but...

小程序报错

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

在开发工具上会二次渲染,但是在手机上就不能了,而且这个报错是时有时无的,求大神分享一下报错的原因,该如何排查呢


回答关注问题邀请回答
收藏

2 个回答

  • 小程序技术专员-SgLy
    小程序技术专员-SgLy
    2018-07-30

    麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题

    2018-07-30
    有用
    回复 2
    • 爱死三土啦
      爱死三土啦
      2018-07-30

      大佬您好,相关片段就是全部,因为这个问题没有具体描述是哪一行代码出了问题了。。如果可以,我可以把代码打包邮箱发给您。。

      2018-07-30
      回复
    • 爱死三土啦
      爱死三土啦
      2018-07-30

      大佬,我在楼里面贴了些代码,麻烦帮忙看一下~

      2018-07-30
      回复
  • 爱死三土啦
    爱死三土啦
    2018-07-30

    在网上也有人遇见同样的问题了


    解决方案:在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进行赋值之外没有任何取值的操作呀

    2018-07-30
    有用
    回复
登录 后发表内容