Skip to content
This repository has been archived by the owner. It is now read-only.

Commit 9b16df2

Browse files
committed
Fix bug in throttle function
1 parent 67f48c8 commit 9b16df2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/utils.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ export function extend (target, source) {
66

77
export function throttle (fn, delay) {
88
let timer = null;
9-
return () => {
9+
return function() {
10+
const context = this;
11+
const args = arguments;
1012
clearTimeout(timer);
1113
timer = setTimeout(() => {
12-
fn();
14+
fn.apply(context, args);
1315
}, delay);
1416
};
1517
}

src/vue-enhanced-scroller.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,15 @@
220220
221221
handleScroll() {
222222
if (this.checkBottomReached()) {
223-
throttle(() => {
224-
this.$emit('infinite-scroll');
225-
}, 100)();
223+
this.$emit('infinite-scroll');
226224
}
227225
},
228226
229227
bindEvents() {
230228
this.scrollEl.addEventListener('touchstart', this.handleTouchStart);
231229
this.scrollEl.addEventListener('touchmove', this.handleTouchMove);
232230
this.scrollEl.addEventListener('touchend', this.handleTouchEnd);
233-
this.scrollEl.addEventListener('scroll', this.handleScroll);
231+
this.scrollEl.addEventListener('scroll', throttle(this.handleScroll, 500));
234232
},
235233
236234
init() {

0 commit comments

Comments
 (0)