From 732c30b33f782c2d2ebb62eacda2fb7a453a7ecd Mon Sep 17 00:00:00 2001
From: admin <344137771@qq.com>
Date: Sat, 31 Jan 2026 11:01:45 +0800
Subject: [PATCH] 1

---
 src/components/elalert.vue |   41 ++++++++++++++++++++++++++++-------------
 1 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/components/elalert.vue b/src/components/elalert.vue
index 275f6df..6fc50ac 100644
--- a/src/components/elalert.vue
+++ b/src/components/elalert.vue
@@ -1,10 +1,11 @@
 <!--  -->
 <template>
     <div v-if="$store.state.elAlertShow">
-        <el-alert  :closable="closable" :title="$store.state.elAlertText" :type="$store.state.elAlertType" center style="z-index:99999999999999999;position: fixed;top: 0;bottom: 0;margin: auto;">
-    </el-alert>
+        <el-alert :closable="closable" :title="$store.state.elAlertText" :type="$store.state.elAlertType" center
+            style="z-index:99999999999999999;position: fixed;top: 0;bottom: 0;margin: auto;">
+        </el-alert>
     </div>
-    
+
 </template>
 
 <script>
@@ -29,37 +30,51 @@
     },
     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.$store.commit('elAlertShow', {'elAlertShow':false});
+                this.timer = setTimeout(() => {
+                    this.$store.commit('elAlertShow', { 'elAlertShow': false });
+                    this.timer = null;
                 }, 2000)
             }
         }
     },
     //生命周期 - 创建完成(访问当前this实例)
     created() {
-        
+
     },
     //生命周期 - 挂载完成(访问DOM元素)
     mounted() {
-        
+
     },
-    methods:{
+    //生命周期 - 销毁前
+    beforeDestroy() {
+        // 组件销毁前清除定时器
+        if (this.timer) {
+            clearTimeout(this.timer);
+            this.timer = null;
+        }
+    },
+    methods: {
         //定时调用父组件方法关闭弹窗
-        closeAlert(){
+        closeAlert() {
             //定时调用父组件方法关闭弹窗
-            setTimeout(()=>{
+            setTimeout(() => {
                 this.$emit('closeAlert')
-            },2000)
+            }, 2000)
         },
-        
+
     }
 }
 </script>

--
Gitblit v1.9.3