Browse Source

Carousel: stop timer before component destroyed (#13820)

HarlanLuo 6 năm trước cách đây
mục cha
commit
23e81831fe
1 tập tin đã thay đổi với 6 bổ sung2 xóa
  1. 6 2
      packages/carousel/src/main.vue

+ 6 - 2
packages/carousel/src/main.vue

@@ -181,11 +181,14 @@ export default {
     },
 
     pauseTimer() {
-      clearInterval(this.timer);
+      if (this.timer) {
+        clearInterval(this.timer);
+        this.timer = null;
+      }
     },
 
     startTimer() {
-      if (this.interval <= 0 || !this.autoplay) return;
+      if (this.interval <= 0 || !this.autoplay || this.timer) return;
       this.timer = setInterval(this.playSlides, this.interval);
     },
 
@@ -257,6 +260,7 @@ export default {
 
   beforeDestroy() {
     if (this.$el) removeResizeListener(this.$el, this.resetItemPosition);
+    this.pauseTimer();
   }
 };
 </script>