scrollTop 頁面滾動的高度,
clientHeight 可視區域高度
scrollHeight 可滾動內容的高度
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;
let param = {
offset: this.offset,
limit: this.limit
}
getArea(param).then((res) => {
if (res.code == 200) {
this.loading = false
this.area = this.area.concat(res.data); //追加數據
if (res.data.length == 0) {
//數據全部加載完成
this.finished = true;
} else {
this.finished = false;
}
}
})
}
}