VUE笔记

VUE中定时器如何使用?

2019-09-26  本文已影响0人  小乙的乙
  1. 定时器的创建和使用
  data() {
    return {
      timer:"",
      value:0
    }
  },
  
    methods: {

    timelog()
    {
      this.value++;
      console.log(this.value);
    }
  },
  
   mounted(){
   // 设置用间隔时间1s,每隔一秒调用一次。
    this.timer = setInterval(this.timelog,1000);
  },
  1. 定时器的销毁
beforeDestroy()
  {
    clearInterval(this.timer)
  }
上一篇 下一篇

猜你喜欢

热点阅读