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

2019-09-03 15:46:32 +08:00
 linbingqinag

目前碰到个问题: 我在 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)
}

1216 次点击
所在节点    问与答
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/597545

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX