vue上拉加载更多

2018-07-30  本文已影响0人  給我小鱼干
<div class="content" ref="scroll" @scroll="loadMore">
...
</div>
loadMore(){
            // 卷去的高度   当前可见区域  总高
          // 触发scroll事件 可能触发n次  先进来开一个定时器,下次触发时将上一次定时器清除掉
          clearTimeout(this.timer); // 节流
          this.timer = setTimeout(()=>{
            let {scrollTop,clientHeight,scrollHeight} = this.$refs.scroll;
            if(scrollTop+clientHeight+20>scrollHeight){
                this.getData(); // 获取更多
            }
          },60);
        },
上一篇 下一篇

猜你喜欢

热点阅读