Applet development: Six (app global variables and callback)

app global variables: globalData, which UserInfo

 

 callback, due app.globalData is to request the network, so there are opportunities there is a delay, there is complete after page onload, due to network reasons, did not get the relevant data.

So here the official app.userInfoReadyCallback callback method, after loading is completed userInfo, will automatically call back the content on the network.

 

  /**
   * Life Cycle function - listen for page loads
   */
  onLoad: function (options) {
    if (app.globalData.userInfo)
    {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    }

  

 

Guess you like

Origin www.cnblogs.com/start2019/p/11886661.html