uniapp 如何让页面的 onLoad 在 onLaunch 之后执行

app.vue里的 onLaunch 中如果有异步方法(比如:登录),返回结果可能会在页面的 onLoad 之后,但 onLoad 中的方法需要登录回调的结果。

为了让页面的 onLoadonLaunch 之后执行,解决方案:

1.main.js

Vue.prototype.$onLaunched = new Promise(resolve => {
    Vue.prototype.$isResolve = resolve;
})

2.app.vue的onLaunch

this.$isResolve()

3.reLaunch重载页面

async onLoad(options) {
    await this.$onLaunched;
}

 

posted @ 2022-09-14 11:28  Oopy  阅读(1031)  评论(0)    收藏  举报