Browse Source

通知公告10秒轮询一次

李文 4 years ago
parent
commit
d47626b9a9
1 changed files with 11 additions and 1 deletions
  1. 11 1
      src/views/main/main-navbar-news.vue

+ 11 - 1
src/views/main/main-navbar-news.vue

@@ -21,7 +21,8 @@ export default {
     return {
       isOpen: false,
       newsNum: 0,
-      noticeNum: 0
+      noticeNum: 0,
+      myInterval: ''
     }
   },
   computed: {
@@ -48,12 +49,21 @@ export default {
   mounted () {
     this.addSelfToAllComponent()
     this.getNews()
+    this.newsInterval()
     // this.getNotice()
   },
+  beforeDestroy () {
+    clearInterval(this.myInterval)
+  },
   methods: {
     addSelfToAllComponent () {
       this.allComponent['main-navbar-news'] = this
     },
+    newsInterval () {
+      this.myInterval = setInterval(() => {
+        this.getNews()
+      }, 1000 * 10)
+    },
     showNews () {
       // this.$parent.$parent.shownews()
       // this.$parent.$refs.navbarmenu.gotoPageByUUID('fe9b5adf20975c1bd13fd38cee3b09a68VfGsVRBgJ3')