setTimeout 代替 setInterval

 delayTime: 1000,
 test1 = 0,
  .
  .
  .
  .
  .
 testTime(){
      const _this = this
      function foo() {
        console.log(new Date());
        _this.test1 = _this.test1 + 1;
        console.log(_this.test1);
        _this.timer = setTimeout(foo, _this.delayTime);
        if (_this.test1 == 30) {
          //符合条件 删除定时器
          console.log("停止");
          clearTimeout(_this.timer);
        }
      }
      foo();
    }

  

原文地址:https://www.cnblogs.com/lucky-jun/p/15047604.html