Skip to content

Commit 6e53384

Browse files
committed
Add the continue fill up feature
1 parent 006acf3 commit 6e53384

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/components/InfiniteLoading.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,19 @@
8383
this.scrollParent = getScrollParent(this.$el);
8484
8585
this.scrollHandler = function scrollHandlerOriginal() {
86-
const currentDistance = getCurrentDistance(this.scrollParent);
87-
if (!this.isLoading && currentDistance <= this.distance) {
88-
this.isLoading = true;
89-
if (this.onInfinite) {
90-
this.onInfinite.call();
91-
}
86+
if (!this.isLoading) {
87+
this.attemptLoad();
9288
}
9389
}.bind(this);
9490
9591
setTimeout(this.scrollHandler, 1);
9692
this.scrollParent.addEventListener('scroll', this.scrollHandler);
9793
9894
this.$on('$InfiniteLoading:loaded', () => {
99-
this.isLoading = false;
10095
this.isFirstLoad = false;
96+
if (this.isLoading) {
97+
this.$nextTick(this.attemptLoad);
98+
}
10199
});
102100
this.$on('$InfiniteLoading:complete', () => {
103101
this.isLoading = false;
@@ -112,6 +110,17 @@
112110
setTimeout(this.scrollHandler, 1);
113111
});
114112
},
113+
methods: {
114+
attemptLoad() {
115+
const currentDistance = getCurrentDistance(this.scrollParent, this.direction);
116+
if (!this.isComplete && currentDistance <= this.distance) {
117+
this.isLoading = true;
118+
this.onInfinite.call();
119+
} else {
120+
this.isLoading = false;
121+
}
122+
},
123+
},
115124
destroyed() {
116125
if (!this.isComplete) {
117126
this.scrollParent.removeEventListener('scroll', this.scrollHandler);

0 commit comments

Comments
 (0)