main.js 1.53 KB
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import VueRouter from "vue-router";
import App from './App.vue'
import routes from "./routes";
import store from './store'
import '@/styles/index.scss'
import '@/components'
import './core/public-path';
import { Common } from '@/utils/common.js'
import Constants from '@/utils/constants.js'
import actions from '@/core/actions';
// import axios from 'axios'
Vue.prototype.btn_size = 'mini'
Vue.prototype.$Common = Common
Vue.prototype.$Constants = Constants
Vue.use(VueRouter);
Vue.use(ElementUI)
Vue.config.productionTip = false;

let router = null;
let instance = null;

function render({ data = {} , container } = {}) {
  router = new VueRouter({
    base: window.__POWERED_BY_QIANKUN__ ? '/system' : '/',
    routes,
  });
  store.state.baseURL = data.baseURL;
  instance = new Vue({
    router,
    store,
    data(){
      return {
        parentRouter: data.router,
        parentVuex: data.store
      }
    },
    render: h => h(App),
  }).$mount(container ? container.querySelector('#glsx-sub-system') : '#glsx-sub-system');
}

if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log('vue app bootstraped');
}

export async function mount(props) {
  console.log('props from main framework', props.data);
  actions.setActions(props);
  render(props);
  props.setGlobalState({

  })
}

export async function unmount() {
  instance.$destroy();
  instance.$el.innerHTML = "";
  instance = null;
  router = null;
}