scrollTop 页面滚动的高度,
clientHeight 可视区域高度,
scrollHeight 可滚动内容的高度
在组件mounted函数中添加滚动事件,检测滚动到页面底部
mounted(){
window.addEventListener('scroll', this.scrollBottom)
},
// 滚动到页面底部时,请求内容scrollBottom() {
this.loading = false
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
let clientHeight = document.documentElement.clientHeight;
let scrollHeight = document.documentElement.scrollHeight;
let bottomOfWindow = scrollTop + clientHeight >= scrollHeight-4
console.log(scrollHeight)
if (scrollTop!=0&&bottomOfWindow && this.loading == false &&this.finished == false) {
this.loading = true
this.offset = this.offset + this.limit;