Skip to content

Commit 29d51cb

Browse files
committed
fix: onDestory清除消息元素以防止内存泄漏
1 parent 31cd9ab commit 29d51cb

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/lib/message/src/message-method.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export function close(id: string, userOnClose?: (vm: VNode) => void): void {
9090

9191
const removedHeight = vm.el!.offsetHeight;
9292
instances.splice(idx, 1);
93+
console.log(userOnClose, vm);
9394

9495
// adjust other instances vertical offset
9596
const len = instances.length;
@@ -101,4 +102,13 @@ export function close(id: string, userOnClose?: (vm: VNode) => void): void {
101102
instances[i].vm.component!.props.offset = pos;
102103
}
103104
}
105+
106+
export function closeAll(): void {
107+
for (let i = instances.length - 1; i >= 0; i--) {
108+
const instance = instances[i].vm.component;
109+
(instance?.proxy as any)?.close();
110+
}
111+
}
112+
113+
message.closeAll = closeAll;
104114
export default message;

src/lib/message/src/message.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
leave-active-class="animate__zoomOut"
55
enter-active-class="animate__zoomIn"
66
@before-leave="onClose"
7-
@after-leave="$emit('destory')"
7+
@after-leave="$emit('destroy')"
88
>
99
<div
1010
class="jw-message animate__animated"

0 commit comments

Comments
 (0)