Browse Source

fix(infiniteloading): keepalive remove event bug

richard1015 4 years ago
parent
commit
47a2e43bdb
1 changed files with 22 additions and 1 deletions
  1. 22 1
      src/packages/__VUE/infiniteloading/index.vue

+ 22 - 1
src/packages/__VUE/infiniteloading/index.vue

@@ -37,7 +37,10 @@ import {
   onUnmounted,
   reactive,
   computed,
-  CSSProperties
+  CSSProperties,
+  onActivated,
+  onDeactivated,
+  ref
 } from 'vue';
 import { createComponent } from '../../utils/create';
 const { componentName, create } = createComponent('infiniteloading');
@@ -268,6 +271,24 @@ export default create({
       );
     });
 
+    const isKeepAlive = ref(false);
+
+    onActivated(() => {
+      if (isKeepAlive.value) {
+        isKeepAlive.value = false;
+        scrollListener();
+      }
+    });
+
+    onDeactivated(() => {
+      isKeepAlive.value = true;
+      state.scrollEl.removeEventListener(
+        'scroll',
+        handleScroll,
+        props.useCapture
+      );
+    });
+
     return {
       classes,
       ...toRefs(state),