main.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // The Vue build version to load with the `import` command
  2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
  3. import "./public-path.js"
  4. import Vue from 'vue'
  5. import Router from 'vue-router'
  6. import App from './App'
  7. import VueI18n from 'vue-i18n'
  8. import routes from './router/index.js'
  9. import PcClientComponent from 'pc-client-component';
  10. // bug fixed by jack
  11. // 在加载 css 的时候 font 不能被正确的加载
  12. import './assets/summernote.css';
  13. Vue.config.productionTip = false
  14. Vue.use(Router)
  15. // 国际化
  16. Vue.use(VueI18n);
  17. moment.locale('zh');
  18. let router = null;
  19. let instance = null;
  20. let i18n = null;
  21. function render(props = {}) {
  22. const { container } = props;
  23. router = new Router({
  24. base: window.__POWERED_BY_QIANKUN__ ? ((process.env.NODE_ENV === 'production') ? '/' : '/pcapp/') : '/',
  25. mode: 'hash',
  26. routes: routes,
  27. });
  28. i18n = new VueI18n({
  29. locale: 'zh-CN',
  30. messages: {
  31. 'zh-CN': require('./lang/zh-CN.js'),
  32. 'en-US': require('./lang/en-US.js'),
  33. }
  34. })
  35. // PC Client 组件
  36. Vue.use(PcClientComponent);
  37. instance = new Vue({
  38. router,
  39. i18n,
  40. render: (h) => h(App),
  41. }).$mount(container ? container.querySelector('#app-client-trace') : '#app-client-trace');
  42. }
  43. // 独立运行时
  44. if (!window.__POWERED_BY_QIANKUN__) {
  45. render();
  46. }
  47. /**
  48. * bootstrap 只会在微应用初始化的时候调用一次,下次微应用重新进入时会直接调用 mount 钩子,不会再重复触发 bootstrap。
  49. * 通常我们可以在这里做一些全局变量的初始化,比如不会在 unmount 阶段被销毁的应用级别的缓存等。
  50. */
  51. export async function bootstrap() {
  52. console.log('[client-trace] bootstraped');
  53. }
  54. /**
  55. * 应用每次进入都会调用 mount 方法,通常我们在这里触发应用的渲染方法
  56. */
  57. export async function mount(props) {
  58. console.log('[client-trace] props from main framework', props);
  59. render(props);
  60. }
  61. /**
  62. * 应用每次 切出/卸载 会调用的方法,通常在这里我们会卸载微应用的应用实例
  63. */
  64. export async function unmount() {
  65. instance.$destroy();
  66. instance.$el.innerHTML = '';
  67. instance = null;
  68. router = null;
  69. }