瀏覽代碼

清理timeout和interval

任一存 3 年之前
父節點
當前提交
6f41a7b1ac
共有 3 個文件被更改,包括 9 次插入1 次删除
  1. 3 0
      src/views/AppCover.vue
  2. 3 0
      src/views/Home.vue
  3. 3 1
      src/views/TreeAnimation.vue

+ 3 - 0
src/views/AppCover.vue

@@ -116,6 +116,9 @@ export default {
       }
     }, 41)
   },
+  destroyed() {
+    clearInterval(this.intervalId)
+  },
   methods: {
     onImgLoad(idx) {
       if (idx < 100) {

+ 3 - 0
src/views/Home.vue

@@ -91,6 +91,9 @@ export default {
       }
     }, 41)
   },
+  destroyed() {
+    clearInterval(this.intervalId)
+  },
   methods: {
     onImgLoad(idx) {
       if (idx < 100) {

+ 3 - 1
src/views/TreeAnimation.vue

@@ -52,6 +52,7 @@ export default {
       },
       requestAnimationId: null,
       treeImageNode: null,
+      timeoutId: null,
     }
   },
   computed: {
@@ -61,6 +62,7 @@ export default {
   },
   destroyed() {
     cancelAnimationFrame(this.requestAnimationId)
+    clearTimeout(this.timeoutId)
   },
   methods: {
     animate() {
@@ -73,7 +75,7 @@ export default {
     onTreeImgLoad() {
       this.showTree = true
 
-      setTimeout(() => {
+      this.timeoutId = setTimeout(() => {
         this.treeImageNode = document.getElementById('tree-image')
         const tween = new TWEEN.Tween(this.animationBottom)
         tween.to({