首页 > 其他分享 >2022-11-18 clearInterval(定时器)无法完全关闭定时器

2022-11-18 clearInterval(定时器)无法完全关闭定时器

时间:2022-11-18 15:45:25浏览次数:50  
标签:11 定时器 2022 18 clearInterval timer 关闭

问题描述:vue+uniapp之小程序定时器业务

原代码:clearInterval(this.timer)

this.timer为定时器的容器,多此点击开启定时器然后就会发现你想使用clearInterval(this.timer)来关闭定时器会发现它还是在运行

 

代码:

    // 开启
    startTimer() {
      this.timer = setInterval(() => {
        this.viime++;
      }, 1000);
    },

    // 关闭
    closeTimer() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },

 

标签:11,定时器,2022,18,clearInterval,timer,关闭
From: https://www.cnblogs.com/iuniko/p/16903442.html

相关文章