其他分享
首页 > 其他分享> > 【VUE】函数内的定时函数的启动与清除

【VUE】函数内的定时函数的启动与清除

作者:互联网

// is_gundong 在我需要的时间内是true 其他时间为false
// timer 用于赋值定时器对象 方便后面清除

 data() {
     return {
               
      // 控制滚动
      is_gundong: false,
      timer: null,
       
      }
  },

 

// watch 

 watch: {
// is_gundong是ture的时候移动 false就移除这个定时器 is_gundong(newData) {if (newData === true) { this.gun() // 这个是我要执行的函数,里面存放着定时器 } else { clearInterval(this.timer) // 清除定时器 } },
},

 

// methods:


gun() {
// 此处略去我要执行的循环逻辑代码 this.timer = setTimeout(this.gun, 200) // 赋值定时器 },

 

标签:定时器,false,函数,gun,timer,VUE,定时,true,gundong
来源: https://www.cnblogs.com/wanghong1994/p/16540477.html