V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
linbingqinag
V2EX  ›  问与答

微信小程序 onLaunch 多个网络请求 首页 onLoad 先执行

  •  
  •   linbingqinag · 2019-09-03 15:46:32 +08:00 · 1191 次点击
    这是一个创建于 1711 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目前碰到个问题: 我在 app.js 中有 3 个网络请求, 在程序启动的时候 index 就是直接 load 起来了, 没有等待 request 完成。

    目前使用了 callback 在 index 但是 callback 还是 没有来的及执行, 有什么比较好的解决方案吗

    // app.js
    
    promisify(wx.checkSession).then(() => {
        return my_getUserInfo(token)
    }).then(resp => {
        if (that.userInfoReadyCallback) {
            that.userInfoReadyCallback(resp)
        }
        console.log("用户信息--get token", this.globalData.userInfo)
    }).catch(err => {
        console.log("登录失败", err)
    });
    
    
    // index.js
    app.userInfoReadyCallback = resp => {
        console.log("call back 获取用户信息");
        redirect2_home(app)
    }
    
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2611 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:56 · PVG 23:56 · LAX 08:56 · JFK 11:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.