2022-08-22 定时多久做什么事情,之后就不做了

 data() {
    return {
      timer:null,
      count:0,
    }
  },
//方法
    setTime(){
        const TIME_COUNT = 3;
        if (!this.timer) {
            this.count = TIME_COUNT;
            this.timer = setInterval(() => {
                if (this.count > 0 && this.count <= TIME_COUNT) {
                    this.count--;
                    var flag = 0;
                    var text = document.getElementById("myDiv");
                    if (!flag&&this.count>0){
                         text.className= "warpNum";
                         flag = 1;
                    }else{
                        text.className = "warpNumDefault";
                        flag = 0;
                    }
                } else {
                    clearInterval(this.timer);
                    this.timer = null;
                }
            }, 30000)
        }
    },

this.setTime()调用

你可能感兴趣的:(2022-08-22 定时多久做什么事情,之后就不做了)