Explorar o código

增加去除定时器

秦鹏 %!s(int64=3) %!d(string=hai) anos
pai
achega
5cbbfae807
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      src/components/Header.vue

+ 8 - 1
src/components/Header.vue

@@ -187,6 +187,7 @@ export default {
       userShow: false,
       language_list: [],
       lang: "",
+      headTimer: null,
     };
   },
   watch: {},
@@ -417,11 +418,17 @@ export default {
       });
     }
     _this.getLangList();
-    _this.getNotReadMessage();
+    _this.headTimer = _this.getNotReadMessage();
     setInterval(() => {
       _this.getNotReadMessage();
     }, 120000);
   },
+  beforeDestroy() {
+    if (this.headTimer) {
+      //如果定时器还在运行 或者直接关闭,不用判断
+      clearInterval(this.headTimer); //关闭
+    }
+  },
 };
 </script>