JS——setInterval定时器的使用
7/10/2022

文章链接:https://blog.csdn.net/qq_43201350/article/details/119145704

 data () {
    return {
      timeR: null,
      timeE: 0,
    }
  },
  methods: {
    demo () {
      this.timeR = null
      this.timeR = setInterval(() => {
        this.timeE += 1
      }, 1000)
      // 以下是要使用定时器的函数
      // this.timeTest() ...
    },
    timeTest () {
      if (this.timeR) {
        clearInterval(this.timeR)
        this.timeE = 0
        console.log('超时了');
      }
      return
      // 以下事件就被中断了
      // ...
    }
  }