| | |
| | | }, |
| | | 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) |
| | | } |
| | | } |
| | |
| | | mounted() { |
| | | |
| | | }, |
| | | //生命周期 - 销毁前 |
| | | beforeDestroy() { |
| | | // 组件销毁前清除定时器 |
| | | if (this.timer) { |
| | | clearTimeout(this.timer); |
| | | this.timer = null; |
| | | } |
| | | }, |
| | | methods: { |
| | | //定时调用父组件方法关闭弹窗 |
| | | closeAlert() { |