fix: notification onClose event runs repeatedly (#6150)

pull/6152/head
Konv Suu 2022-12-11 14:49:02 +08:00 committed by GitHub
parent 5b3ade8980
commit 7ea18a8287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -46,9 +46,10 @@ export default defineComponent<NoticeProps>({
] as any, ] as any,
setup(props, { attrs, slots }) { setup(props, { attrs, slots }) {
let closeTimer: any; let closeTimer: any;
const duration = computed(() => (props.duration === undefined ? 1.5 : props.duration)); let isUnMounted = false;
const duration = computed(() => (props.duration === undefined ? 4.5 : props.duration));
const startCloseTimer = () => { const startCloseTimer = () => {
if (duration.value) { if (duration.value && !isUnMounted) {
closeTimer = setTimeout(() => { closeTimer = setTimeout(() => {
close(); close();
}, duration.value * 1000); }, duration.value * 1000);
@ -79,6 +80,7 @@ export default defineComponent<NoticeProps>({
startCloseTimer(); startCloseTimer();
}); });
onUnmounted(() => { onUnmounted(() => {
isUnMounted = true;
clearCloseTimer(); clearCloseTimer();
}); });