废话不多说 上代码
<div class="content" ref="scroll" @scroll="handleScroll">
<child :file-list="fileList"></child>
</div>
handleScroll:function() {
var that = this;
clearTimeout(this.timer)
this.timer = setTimeout(()=>{
let { scrollTop,clientHeight,scrollHeight} = this.$refs.scroll;
if(scrollTop+clientHeight+20>scrollHeight){
//加载方法
}
},13)
},
scrollTop失效问题
有两种解决方法
- 就是给content 加固定的高度;
- 使用 fixed定位
此方法适用于页面有一个固定高度的头部导航
.content {
position: fixed;
top: 50px;
left: 0;
right: 0;
bottom: 0;
overflow: auto
}
本文详细介绍了在Vue中实现滚动监听的方法,通过代码示例展示了如何使用@scroll事件结合setTimeout来避免频繁触发导致的性能问题。同时,文章还探讨了解决scrollTop失效问题的两种策略:为content设置固定高度及使用fixed定位。
3691

被折叠的 条评论
为什么被折叠?



