2020 <slot ></slot >
2121
2222 <!-- 上拉加载 -->
23- <div class =" vuejs-loadmore" >
23+ <div class =" vuejs-loadmore" ref =" placeholder" >
24+
2425 <div class =" vuejs-loadmore-loading" v-if =" loadLoading && !finished && !error" >
2526 <Loading >{{ loadingText || t(`loadmore.loading`) }}</Loading >
2627 </div >
3334 {{ errorText || t(`loadmore.error`) }}
3435 </div >
3536
36- <div ref =" placeholder" class =" vuejs-loadmore-placeholder" />
3737 </div >
3838 </div >
3939 </div >
@@ -47,6 +47,7 @@ import { TimeoutMixin } from '../mixins/timer';
4747// utils
4848import { preventDefault } from ' ../utils/event' ;
4949import { getScroller , getScrollTop } from ' ../utils/scroll' ;
50+ import { throttle } from ' ../utils/throttle' ;
5051import locale from ' ../locale' ;
5152// Icon
5253import Loading from ' ../icon' ;
@@ -62,7 +63,8 @@ export default {
6263 this .scroller = getScroller (this .$el );
6364 }
6465
65- bind (this .scroller , ' scroll' , this .checkSroll );
66+ // scroll节流
67+ bind (this .scroller , ' scroll' , throttle (this .checkSroll , 200 ));
6668 }),
6769 TimeoutMixin
6870 ],
@@ -286,9 +288,8 @@ export default {
286288 }
287289
288290 const placeholderRect = this .$refs .placeholder .getBoundingClientRect ();
289- const bottomDistance = placeholderRect .bottom - scrollerRect .bottom ;
290- // placeholderRect在scrollerRect外面而不是里面(>0),并且在底部位置(<= loadOffset)
291- const bottomReached = bottomDistance > 0 && bottomDistance <= loadOffset;
291+ // 取绝对值,placeholderRect在scrollerRect容器的正负loadOffset区间则达到底部
292+ const bottomReached = Math .abs (placeholderRect .bottom - scrollerRect .bottom ) <= loadOffset;
292293
293294 if (bottomReached) {
294295 this .loadLoading = true ;
0 commit comments