vue中定时向后台调用数据接口和清除定时器

tech2025-07-24  6

这里是启用定时器。this.getlist是我调用的下面自己封装的接口

//这里是我调用的接口,接口是在methods里面写的,这里就不写了 //这里需要在data里面写timer:null created() { this.timer=setInterval(() => { this.getList(); this.getListmiddle(); this.getListlast(); console.log(111); }, 500); }, var foo = 'bar';

下面是清除定时器

//销毁定时器 beforeDestroy() { if (this.timer) { console.log("销毁定时器") clearInterval(this.timer); //在Vue实例销毁前,清除我们的定时器 } } var foo = 'bar';
最新回复(0)