@vue定时器和关闭定时器

vue定时器和关闭定时器

 mounted() {//页面加载完成后执行方法(启动定时器)
  clearInterval(this.timer)
   		 this.setTimer()
  },
  //distroyed: function () {//页面关闭后关闭定时器(并没用)
    //  console.log('distroyed')
   // clearInterval(this.timer)
  //},
  beforeDestroy() {//页面关闭前关闭定时器 (这个才有用)
      clearInterval(this.timer)
  },
  methods: {
    setTimer: function () {
    this.timer = setInterval( () => {
              console.log("定时执行方法");
      }, 3000);
  },
 }

vue生命周期 学习
https://segmentfault.com/a/1190000008010666

Logo

智屏生态联盟致力于大屏生态发展,利用大屏快应用技术降低开发者开发、发布大屏应用门槛

更多推荐