Skip to content
内容大纲
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

启动时同步加载配置

启动时候,同步加载配置

  • 创建项目/src/plugins/bindGlobal/base-init.js
js
import Vue from "vue";

Vue.prototype.$onLaunched = new Promise((resolve) => {
  Vue.prototype.$isResolve = resolve;
});
  • 项目/src/App.vue
vue
<script>
export default{
  onLaunch(){
    // 加载配置
    console.log('---加载 1---');
    this.initLoadConfig();
  },
  methods:{
    async initLoadConfig(){
      console.log('---加载 2---');
      await localRemoteConf1();
      await localRemoteConf2();
      await localRemoteConf3();
      this.$isResolve();
      console.log('---加载 3---');
    }
  }
}
</script>
  • 项目/src/pages/index.vue
vue
<template>

</template>
<script>
export default{
  async onLoad(){
    uni.showLoading({ title: '加载中' });
    await this.$onLaunched;
    console.log('---加载 4---');
    uni.hideLoading();
  },
}
</script>

刷新执行后,控制台会依次输出

html
---加载 1---
---加载 2---
---加载 3---
---加载 4---

参考

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发