data() {
return {
codeTimer: null,//定时器
codeTime: 12, // 限制1分钟后没请求到erp数据,不再继续请求
};
},
//开启定时器 通过codeTime的值来判断是否需要定时器
_codeCount() {
this.codeTimer = window.setInterval(() => {
if (this.codeTime <= 0) {
console.log('清楚定时器');
//通过window来清除定时器
window.clearInterval(this.codeTimer);
this.codeTimer = null;
this.codeTime = 0;
/* 清除定时的逻辑*/
} else {
/*未请求到接口,继续请求数据*/
//this.getErpTableDataList();
this.codeTime--;
}
console.log(this.codeTime, 'this.codeTime');
}, 5000);
},
//清除定时器
_clearCount() {
window.clearInterval(this.codeTimer);
this.codeTimer = null;
this.codeTime = 0;
},
vue项目:开启定时器后,1分钟内每5秒调一次接口,请求到数据后,清除定时器
于 2022-09-29 14:46:37 首次发布