
正文
【VUE】vue项目开发中,setTimeout等定时器的管理。
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如果在一个组件中使用了定时器,当通过路由切换页面的时候
1、如果有同一个组件,定时器会叠加。
解决方案:
computed:{
timer: {
set (val) {
this.$store.state.timeout = val;
},
get() {
return this.$store.state.timeout;
}
},
},
mounted(){
if ( this.timer ) {
clearInterval(this.timer);
}
//定时发请求
var self=this;
this.timer=setInterval(function(){
//执行事件
},2000)
}






