linbingqinag
V2EX  ›  问与答

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

  •  
  •   linbingqinag · Sep 3, 2019 · 1474 views
    This topic created in 2447 days ago, the information mentioned may be changed or developed.

    目前碰到个问题: 我在 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)
    }
    
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2952 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 05:30 · PVG 13:30 · LAX 22:30 · JFK 01:30
    ♥ Do have faith in what you're doing.