场景:1.数据量巨大2.请求接口每隔几秒刷新一次数据查询数据时,由于参数和数据量大,可能返回数据比较慢查询数据库时。导致接口超时报错等,所以需要每隔10秒轮询一次查询接口。Method:setInterval,setTimeout//querysearch(){constdelayTime=60*1000letres=this.getData()if(res===0){//清除定时器clearInterval(this.timer)console.log('查询成功')}else{console.log('查询超时')//清除定时器clearInterval(this.timer)this.timer=setInterval(()=>{this.search()},delayTime)}},//查询数据getData(){}注意:setInterval需要清空定时器队列,每次重复执行都会造成定时器叠加,setInterval也要在销毁循环中清空
