有两种方案可以实现,浏览器需要支持es6
方案一
1、main.js添加如下代码Vue.prototype.$onLaunched = new Promise(resolve => {
Vue.prototype.$isResolve = resolve
})2、应用启动时,设置需要等待的逻辑
在 App.vue 的 onLaunch 中增加代码 this.$isResolve()
这个方法必须在你的业务如ajax执行完毕后再执行另外注意要用箭头函数,否则this不好使
onLaunch: function() {
console.log('App Launch');
console.log('倒计时10秒');
setTimeout(() => {
console.log('倒计时结束');
this.$isResolve()
},5000);
},3、在页面 onLoad 中增加等待代码 await this.$onLaunched
注意onload要添加async,否则编译不过去
async onLoad(option) {
//等待倒计时
await this.$onLaunched;
console.log("等待倒计时结束后打印");
// 后续业务逻辑
},4、在chrome运行截图如下,小程序等支持ES6环境才行

方案二
1、main.js
Vue.prototype.$visitStore = async (option)=>{
//页面入参option
//自己的业务逻辑
//如果是ajax,注意要加同步等待
await Vue.prototype.http.post('/customer/updateLastVisitStoreId',{lastVisitStoreId:storeId}).then(res => {
console.log(res);
}).catch(err => {
console.log(err);
})
}2、页面async onLoad(option) {
await this.$visitStore(option);//同步执行这个方法
} 网友回复
如何写ai提示词让大模型根据主题生成视频脚本json,然后让Hyperframe渲染出mp4视频?
有哪些字体使用等宽编程代码展示?
如果让演唱会歌迷的上万手机屏幕和闪光灯一起被现场中控控制闪烁?
Midjourney为啥进军医疗领域了?
python如何跟踪足球比赛指定球员全场运动标注打聚光灯合成
如何将linux服务器的文件目录映射到windows电脑磁盘?
Docling 与 MarkItDown 两个库有啥不同?
豆包收费后国产其他ai软件也会跟进收费吗?
JPEG 与 HEIF图片格式区别?
centos7版本太旧无法安装python3.11,如何在docker中运行python3.11?


