onload事件什么时候触发,pageload事件何时触发
uniapp上的onLaunch异步方法和onLoad执行顺序问题说明:
在uniapp中,如果app.vue的onLaunch具有异步方法(如登录方法),则返回结果可能在页面的onLoad之后。 要确保页面的onLoad在onLaunch之后运行,请使用以下解决方案:
1、main.js添加以下代码
在vue.prototype.$ onlaunched=new promise (resolve={ vue.prototype.$ is resolve=resolve } ) 2、App.vue的on launch上
这个方法必须在你的业务,比如ajax执行结束后再执行
on launch : function ((const that=this/) ifdefMP-weixinuni.getprovider ) )服务: ' oauth ', //success(RES ) if ) RES.provider.indexof ) ' weixin'-1 ) )/weixin小程序为代码uni.login ) provider3360'weiin 将登录信息存储在与sessionKey等loginbywechatcode ({ code : wres.code }.then ) ) login={}交换代码的login//vuex中的then . login.data ) if ) login.code==0) ) that.$ isresolvving log in.data.talents _ token (uni.switch tab ) ({ URL 3: showCancel: false、success(RES ) if (RES.confirm ) uni.redirectto ) ) URL : (/pages/log in/logi npage ) ) catch(e ) console.error(e ) } )//#endif} ),3,在页面onLoad中添加代码awaitthis.$onlaunched3333
await this.$onLaunched,等待同步加载(选项)//登录成功; //后续业务逻辑}