vuejs移动端实现滚动到底部自动分页
1、先创建2个参数,pageNum当前页码,totalCount总页面
data(){
return:{
pageNum: 1,
totalCount: 0
}
}
2、在created()创建一个滚动scroll监听
// 监听滚动条
window.addEventListener("scroll", () => {
//滚动条滚动时,距离顶部的距离
let scrollTop =
document.documentElement.scrollTop || document.body.scrollTop;
//windowHeight是可视区的高度
let windowHeight =
document.documentElement.clientHeight || document.body.clientHeight;
//scrollHeight是滚动条的总高度
let scrollHeight =
document.documentElement.scrollHeight || document.body.scrollHeight;
//判断是否到底了
if (scrollTop + windowHeight > scrollHeight - 50) {
//根据当前页码和总页面的判断是否再执行接口
if (this.pageNum < this.totalCount) {
this.pageNum += 1;
this.getPageData();
}
}
});
以上是编程学习网小编为您介绍的“vuejs移动端实现滚动到底部自动分页”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。