Skip to content

Commit

Permalink
feat:vue3微前端改造
Browse files Browse the repository at this point in the history
  • Loading branch information
dL-hx committed Aug 28, 2022
1 parent 1ccc072 commit 1f1dfe7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vue2/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ export const mount = ()=>{

export const unmount = ()=>{
console.log("卸载", instance);
// 卸载时候卸载vue实例
// 卸载时候卸载vue实例,卸载事件,清空当前根元素的内容
}
32 changes: 31 additions & 1 deletion vue3/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,34 @@ import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

createApp(App).use(router).mount('#app')
let instance = null // 定义对象接收实例


const render = () => {
instance = createApp(App)
// 挂载vue实例
instance.use(router).mount('#app')
}

if (!window.__MICRO_WEB__) { // 如果不是微前端环境,执行render
render()
}

// 如果在微前端环境,暴露生命周期

// 开始加载结构 (加载前的处理, 如参数处理..)
export const bootstrap = () => {
console.log("开始加载");
}


//
export const mount = () => {
console.log("渲染成功");
render()
}

export const unmount = () => {
console.log("卸载", instance);
// 卸载时候卸载vue实例,卸载事件,清空当前根元素的内容
}

0 comments on commit 1f1dfe7

Please sign in to comment.