vue 在keep-alive页面 使用定时 监听路由的方式

vue yekong 1359℃
  mounted() {
    this.createTiming()
  },
  watch: {
    $route(to, from) {
      if (this.$route.path != '/videoList') {
        this.destroyTiming()
      } else {
        this.createTiming()
      }
    }
  },
destroyTiming() {
      clearInterval(this.timer);
      console.log('销毁定时')
    },
    createTiming() {
      localStorage.setItem("lastTime", new Date().getTime());
      // 每3秒 调用检查时间的方法
      // 创建定时
      this.timer = setInterval(this.checkTimeout, 3000);
      // 页面监听 按下鼠标更新操作时间
      window.onload = function () {
        window.document.onmousedown = function () {
          localStorage.setItem("lastTime", new Date().getTime());
        }
      };
    },
喜欢 (1)