小程序首页onLaunch,onLoad为异步,调用app.js中的全局参数的解决方案。
发布于 3 年前 作者 lujun 3826 次浏览 来自 分享

解决方案就是在app.js加一个回调函数

   wx.login({
        failres => {
          console.log(res)
        },
        successres => {
          util.request(api.dl, {
            code: res.code,
          }, "GET").then(res => {
            if (this.employIdCallback){
              this.employIdCallback(res);
           }
            this.globalData.userid=res
            

然后在你的首页onLoad进行判断是否有这个值然后进行不同的逻辑

onLoad: function (options) {
   
    console.log( )
    if(!app.globalData.userid){
      this.getstore()
      this.getfl()
    }else{
      app.employIdCallback= param1=> {
        this.getstore()
        this.getfl()
   }
    }
   
   
  },

1 回复

试试promise你会打开新世界大门

回到顶部