Skip to content

Commit a01a3e1

Browse files
authored
feat: 增加 mounted 和 beforeUnmount 两个钩子 (#4)
* feat: 增加 beforeUnmount 可以在销毁前调用 vue 实例 * feat: 增加 mounted hook * docs: 增加钩子例子
1 parent 2b69156 commit a01a3e1

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

README-zh.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ yarn add @femessage/nuxt-micro-frontend -D
5454
## 微前端生命周期函数例子
5555
[Qiankun](https://github.com/lianghx-319/micro-nuxt/blob/master/example/mfe.js)
5656

57+
- 增加了 `mounted``beforeUnmount` 两个钩子方便操作 vue 实例
58+
5759
## 开发
5860

5961
1. 克隆此仓库

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ yarn add @femessage/nuxt-micro-frontend -D
5454
## LifeCycle hooks file example
5555
[Qiankun](https://github.com/lianghx-319/micro-nuxt/blob/master/example/mfe.js)
5656

57+
- add `mounted` and `beforeUnmount` hook to get vue instance
58+
5759
## Development
5860

5961
1. Clone this repository

example/mfe.js

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export async function mount (render, props) {
1414
console.log('props from main framework', props)
1515
}
1616

17+
export function mounted (vm) {
18+
console.log(vm)
19+
}
20+
21+
export function beforeUnmount (vm) {
22+
console.log(vm)
23+
}
24+
1725
export function unmount () {
1826
console.log('nuxt app unmount')
1927
}

lib/client.js

+2
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ export async function bootstrap() {
101101

102102
export async function mount(props) {
103103
MFE.mount && await MFE.mount(renderNuxt, props)
104+
MFE.mounted && instance && await MFE.mounted(instance, props)
104105
}
105106

106107
export async function unmount() {
108+
MFE.beforeUnmount && await MFE.beforeUnmount(instance)
107109
instance.$destroy()
108110
instance = null
109111
router = null

0 commit comments

Comments
 (0)