Browse Source

fix: swiper的销毁钩子内计时器清空无效 #262

richard1015 5 years ago
parent
commit
90c26c0e16
1 changed files with 17 additions and 14 deletions
  1. 17 14
      src/packages/swiper/swiper.vue

+ 17 - 14
src/packages/swiper/swiper.vue

@@ -1,26 +1,18 @@
 <template>
-  <div class="nut-swiper" :class="[direction, { dragging: dragging }]" @touchstart="_onTouchStart($event)" @mousedown="_onTouchStart($event)">
-    <div
-      class="nut-swiper-wrap"
-      :style="{
+  <div class="nut-swiper" :class="[direction, { dragging: dragging }]" @touchstart="_onTouchStart($event)"
+    @mousedown="_onTouchStart($event)">
+    <div class="nut-swiper-wrap" :style="{
         transform: 'translate3d(' + translateX + 'px,' + translateY + 'px,0)',
         'transition-duration': transitionDuration + 'ms',
         '-webkit-transform': 'translate3d(' + translateX + 'px,' + translateY + 'px,0)',
         '-webkit-transition-duration': transitionDuration + 'ms',
         'transition-timing-function': 'ease'
-      }"
-      @transitionend="_onTransitionEnd"
-    >
+      }" @transitionend="_onTransitionEnd">
       <slot></slot>
     </div>
     <div class="nut-swiper-pagination" v-show="paginationVisible">
-      <span
-        class="swiper-pagination-bullet"
-        :class="{ active: index + 1 === currentPage }"
-        v-for="(slide, index) in slideEls"
-        :key="index"
-        @click="paginationClickable && setPage(index + 1, true)"
-      >
+      <span class="swiper-pagination-bullet" :class="{ active: index + 1 === currentPage }"
+        v-for="(slide, index) in slideEls" :key="index" @click="paginationClickable && setPage(index + 1, true)">
       </span>
     </div>
   </div>
@@ -400,6 +392,17 @@ export default {
   destroyed() {
     this.timer = null;
     this.domTimer = null;
+  },
+  activated() {
+    if (this.keepAlive) {
+      this.keepAlive = false;
+      this.updateEvent();
+    }
+  },
+  deactivated() {
+    this.keepAlive = true;
+    this.timer = null;
+    this.domTimer = null;
   }
 };
 </script>