在实际开发中,经常会有轮询的效果。
1、js实现轮询效果==》使用setTimeout,clearTimeout方法
function setTimer () {let timeraxios.post(url, params).then(function (res) {if(res){console.log(res);timer = setTimeout(() => {this.setTimer()}, 5000) }else {clearTimeout(timer) //清理定时任务}}).catch(function (error) {console.log(error);}); },
2.HTML5推出新的对象:websocket