Skip to content

Commit

Permalink
fix: onDestory清除消息元素以防止内存泄漏
Browse files Browse the repository at this point in the history
  • Loading branch information
coderyjw committed Feb 18, 2022
1 parent 31cd9ab commit 29d51cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lib/message/src/message-method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export function close(id: string, userOnClose?: (vm: VNode) => void): void {

const removedHeight = vm.el!.offsetHeight;
instances.splice(idx, 1);
console.log(userOnClose, vm);

// adjust other instances vertical offset
const len = instances.length;
Expand All @@ -101,4 +102,13 @@ export function close(id: string, userOnClose?: (vm: VNode) => void): void {
instances[i].vm.component!.props.offset = pos;
}
}

export function closeAll(): void {
for (let i = instances.length - 1; i >= 0; i--) {
const instance = instances[i].vm.component;
(instance?.proxy as any)?.close();
}
}

message.closeAll = closeAll;
export default message;
2 changes: 1 addition & 1 deletion src/lib/message/src/message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
leave-active-class="animate__zoomOut"
enter-active-class="animate__zoomIn"
@before-leave="onClose"
@after-leave="$emit('destory')"
@after-leave="$emit('destroy')"
>
<div
class="jw-message animate__animated"
Expand Down

0 comments on commit 29d51cb

Please sign in to comment.