vue 滚动底部添加更多数据
话不多说直接上代码:
methosd:{
lazyLoading () { // 滚动到底部,再加载的处理事件
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
let clientHeight = document.documentElement.clientHeight;
let scrollHeight = document.documentElement.scrollHeight;
if (scrollTop + clientHeight >= scrollHeight) { // 如果滚动到接近底部,自动加载下一页
//事件处理
console.log("0000")//此处可以添加数据请求
}
}
}
在生命周期moutend 函数中执行
moutend(){
window.addEventListener('scroll', this.lazyLoading); // 滚动到底部,再加载的处理事件
}