在实际开发中,经常会有轮询的效果。

1、js实现轮询效果==》使用setTimeout,clearTimeout方法

function setTimer () {
         let timer
        axios.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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-28
  • 2021-07-13
  • 2021-11-29
  • 2021-10-29
  • 2021-04-07
  • 2021-08-25
猜你喜欢
  • 2021-06-12
  • 2022-12-23
  • 2022-01-19
  • 2021-08-04
  • 2021-09-28
  • 2021-11-20
  • 2022-01-11
相关资源
相似解决方案