vue 倒计时结束之后“刷新页面“造成死循环

哈哈哈哈哈哈
  • 36

//倒计时

countDown() {
  let count = 0;
  let newTime = new Date().getTime();
  let endTimeList = this.actEndTimeList;
  let countDownArr = [];
  endTimeList.forEach(o => {
    let endTime = new Date(o).getTime();
    let obj = null;
    if (endTime - newTime > 0) {
      let time = (endTime - newTime) / 1000;
      let day = parseInt(time / (60 * 60 * 24));
      let hou = parseInt((time % (60 * 60 * 24)) / 3600) + day * 24;
      let min = parseInt(((time % (60 * 60 * 24)) % 3600) / 60);
      let sec = parseInt(((time % (60 * 60 * 24)) % 3600) % 60);
      obj = {
        hou: this.timeFormat(hou),
        min: this.timeFormat(min),
        sec: this.timeFormat(sec)
      };
    } else {
      obj = {
        hou: "00",
        min: "00",
        sec: "00"
      };
      count++;
    }
    countDownArr.push(obj);
  });
  this.countDownList = countDownArr;
  this.interval = setTimeout(this.countDown, 1000);
  if (count == endTimeList.length) {
    if (this.interval) {
      clearTimeout(this.interval);
      //这一块死循环
      this.$router.go(0)
    }
  }
}















回复
阅读 2.9k
3 个回答

this.$router.go(0) 去掉

this.$router.go(0)
这段代码是最根本原因,换一种实现方式

吧这个换一下顺序


  if (count == endTimeList.length) {
    if (this.interval) {
      clearTimeout(this.interval);
      //这一块死循环
      this.$router.go(0)
    }
  }
 // 这个放到最下面
  this.interval = setTimeout(this.countDown, 1000);
宣传栏