1
admin
2026-01-28 03ec19e1313fa30b8039f3ce507efb11242dd3ec
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() {