微前端-主项目和子项目

134 阅读1分钟
  1. 如何加载子模块?

let timestamp = new Date().getTime(); ipPath/modules/ele.systemCode{ele.systemCode}-{ele.code}/app.js?v=${timestamp}`

window.System.import(compUrl)// 模块加载器导入js模块,需要相对路径或者绝对路径

  1. 子模块打包后的html 有什么用? 独立启动时网页入口

  2. 路由是什么时候添加的? 子模块mount声明周期时,将后端查询资源管理菜单中配置的路由返回到前端,然后router.addRoute添加到路由中。 可以优化为:动态路由加载

  3. 子模块之间如何通信 维护同一份vuex,通过script标签引入vuex

window.Vue = Vue
window.Vuex = Vuex
window.Vue.use(window.Router)
window.Vue.use(window.Vuex)

基座和子模块的通信

singleSpa.mountRootParcel(appModel, {
    appName: app.name,
    domElement: document.getElementById(app.name),
    keepAliveTabs: store.state.keepAliveTabs[app.name],
    store: store.state.outputStore,
    dynamicRoutes: currentAppRoutes
});