From 03ec19e1313fa30b8039f3ce507efb11242dd3ec Mon Sep 17 00:00:00 2001
From: admin <344137771@qq.com>
Date: Wed, 28 Jan 2026 17:28:08 +0800
Subject: [PATCH] 1
---
src/components/elalert.vue | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/src/components/elalert.vue b/src/components/elalert.vue
index 11a0cda..6fc50ac 100644
--- a/src/components/elalert.vue
+++ b/src/components/elalert.vue
@@ -30,16 +30,22 @@
},
data() {
return {
-
+ timer: null // 保存定时器引用
}
},
//监听alertShow变成true时,2秒后自动关闭
watch: {
// 监听vuex中的elAlertShow变化
'$store.state.elAlertShow': function (val) {
+ // 清除之前的定时器
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = null;
+ }
if (val) {
- setTimeout(() => {
+ this.timer = setTimeout(() => {
this.$store.commit('elAlertShow', { 'elAlertShow': false });
+ this.timer = null;
}, 2000)
}
}
@@ -52,6 +58,14 @@
mounted() {
},
+ //生命周期 - 销毁前
+ beforeDestroy() {
+ // 组件销毁前清除定时器
+ if (this.timer) {
+ clearTimeout(this.timer);
+ this.timer = null;
+ }
+ },
methods: {
//定时调用父组件方法关闭弹窗
closeAlert() {
--
Gitblit v1.9.3