Skip to content

Commit efc54f4

Browse files
committed
feat: useFaModaluseFaDrawer 页面卸载时自动清理
1 parent 0b9d11f commit efc54f4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/ui/components/FaDrawer/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,19 @@ export function useFaDrawer() {
103103
// 挂载到当前实例
104104
instance?.proxy?.$el?.appendChild(container)
105105

106+
// 监听组件卸载,自动清理
107+
if (instance) {
108+
onUnmounted(() => {
109+
if (vnode) {
110+
render(null, container)
111+
vnode = null
112+
}
113+
if (container.parentNode) {
114+
container.parentNode.removeChild(container)
115+
}
116+
})
117+
}
118+
106119
const open = () => {
107120
visible.value = true
108121
}

src/ui/components/FaModal/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,19 @@ export function useFaModal() {
111111
// 挂载到当前实例
112112
instance?.proxy?.$el?.appendChild(container)
113113

114+
// 监听组件卸载,自动清理
115+
if (instance) {
116+
onUnmounted(() => {
117+
if (vnode) {
118+
render(null, container)
119+
vnode = null
120+
}
121+
if (container.parentNode) {
122+
container.parentNode.removeChild(container)
123+
}
124+
})
125+
}
126+
114127
const open = () => {
115128
visible.value = true
116129
}

0 commit comments

Comments
 (0)