litian
2024-12-27 9a300328b183350f665488c1d3221bfb0acf9a99
src/main.js
@@ -1,16 +1,18 @@
import Vue from "vue";
import App from "./App.vue";
import less from "less";
import "./books/childHealth/assets/main.less";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
import store from "./store";
// 公式输入
import { MathfieldElement } from "mathlive"
Vue.config.productionTip = false;
// 自定义配置
import config from "@/assets/js/config";
Vue.prototype.config = config;
// Vue.prototype.thisBookConfig = await config.getBookConfig();
// 请求处理
import MG from "@/assets/js/middleGround/WebMiddleGroundApi";
@@ -29,14 +31,16 @@
let instance = null;
function render(actions = {}) {
  // const { container } = props;
function render(props = {}) {
  const { container, onGlobalStateChange, setGlobalState } = props;
  Vue.prototype.onGlobalStateChange = onGlobalStateChange;
  Vue.prototype.setGlobalState = setGlobalState;
  Vue.prototype.container = container;
  instance = new Vue({
    // router,
    actions,
    store,
    render: (h) => h(App)
  }).$mount(actions.container ? actions.container.querySelector("#app") : "#app");
  }).$mount(container ? container.querySelector("#app") : "#app");
}
// 独立运行时
@@ -47,16 +51,17 @@
// qiankun
export async function bootstrap() {}
export async function mount(props) {
  console.log(props, "子层获取的props");
  console.log(props, "子层propspropspropsprops");
  props.onGlobalStateChange((state, prev) => {
    // state: 变更后的状态; prev 变更前的状态
    console.log("子层change:",state, prev);
    if (state.bb) state.bb(123)
    console.log("子层变化:", state, prev);
    // 状态变化同步vuex,用于各页面调用
    store.commit("setQiankun", state);
  });
  props.setGlobalState({
    aa: 2
  });
  // props.setGlobalState({
  //   state: 3, // 应用挂载完成,同时用于触发一次stateChange将state挂载在vuex当中
  // });
  render(props);
}
@@ -66,7 +71,7 @@
  instance = null;
}
// new Vue({
//   store,
//   render: (h) => h(App)
// }).$mount("#app");
// 增加 update 钩子以便主应用手动更新微应用
// export async function update(props) {
//   render(props);
// }