MeterSphere/project-management/frontend/src/main.js

87 lines
2.5 KiB
JavaScript
Raw Normal View History

import "./public-path";
import Vue from "vue";
import "metersphere-frontend/src/styles/index.scss";
2022-10-10 13:41:39 +08:00
import ElementUI from "element-ui";
import App from "./App.vue";
2022-10-10 13:41:39 +08:00
import i18n from "./i18n";
import router from "./router";
import { createPinia, PiniaVuePlugin } from "pinia";
import PersistedState from "pinia-plugin-persistedstate";
import icons from "metersphere-frontend/src/icons";
2022-10-10 13:41:39 +08:00
import svg from "metersphere-frontend/src/components/svg";
import plugins from "metersphere-frontend/src/plugins";
import directives from "metersphere-frontend/src/directive";
import filters from "metersphere-frontend/src/filters";
import "metersphere-frontend/src/router/permission";
import mavonEditor from "mavon-editor";
import "mavon-editor/dist/css/index.css";
import VuePapaParse from "vue-papa-parse";
Vue.config.productionTip = false;
2022-10-10 13:41:39 +08:00
const pinia = createPinia();
pinia.use(PersistedState); //开启缓存存储在localstorage
2022-10-10 13:41:39 +08:00
Vue.use(ElementUI, {
i18n: (key, value) => i18n.t(key, value),
2022-10-10 13:41:39 +08:00
});
Vue.use(mavonEditor);
2022-10-10 13:41:39 +08:00
Vue.use(svg);
Vue.use(icons);
Vue.use(plugins);
Vue.use(directives);
Vue.use(filters);
Vue.use(PiniaVuePlugin);
Vue.use(VuePapaParse);
2022-10-10 13:41:39 +08:00
let instance = null;
function render(props = {}) {
const { container, eventBus = new Vue() } = props;
2022-10-10 13:41:39 +08:00
// 添加全局事件总线
Vue.prototype.$EventBus = eventBus;
instance = new Vue({
i18n,
router,
pinia,
render: (h) => h(App),
}).$mount(container ? container.querySelector("#app") : "#app");
2022-10-10 13:41:39 +08:00
}
// 独立运行时
if (!window.__POWERED_BY_QIANKUN__) {
render();
}
/**
* bootstrap 只会在微应用初始化的时候调用一次下次微应用重新进入时会直接调用 mount 钩子不会再重复触发 bootstrap
* 通常我们可以在这里做一些全局变量的初始化比如不会在 unmount 阶段被销毁的应用级别的缓存等
*/
export async function bootstrap(props) {
}
/**
* 应用每次进入都会调用 mount 方法通常我们在这里触发应用的渲染方法
*/
export async function mount(props) {
props.onGlobalStateChange((state, prev) => {
// state: 变更后的状态; prev 变更前的状态
});
props.setGlobalState({ event: "opendialog" });
2022-10-10 13:41:39 +08:00
render(props);
}
/**
* 应用每次 切出/卸载 会调用的方法通常在这里我们会卸载微应用的应用实例
*/
export async function unmount(props) {
instance.$destroy();
}
/**
* 可选生命周期钩子仅使用 loadMicroApp 方式加载微应用时生效
*/
export async function update(props) {
}