<div v-if="loading" style="width: 100%;text-align: center;padding: 20px 0px;">加载中...</div>
data() {
return {
allData: [],
chunkSize: 10,
loading: false,
currentPage: 1 ,
};
},
mounted() {
window.addEventListener('scroll', this.handleScroll);
},
beforeDestroy() {
window.removeEventListener('scroll', this.handleScroll);
},
methods: {
handleScroll() {
const scrollHeight = document.documentElement.scrollHeight;
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
const clientHeight = document.documentElement.clientHeight;
if (scrollHeight - (scrollTop + clientHeight) < 100) {
if(this.list.length >= this.allData.length ){
}else if(this.list.length < this.allData.length && !this.loading){
this.loading = true;
setTimeout(() => {
const startIndex = (this.currentPage - 1) * this.chunkSize;
const endIndex = startIndex + this.chunkSize;
this.list = [...this.list, ...this.allData.slice(startIndex, endIndex)];
this.currentPage++;
this.loading = false;
},1000)
}
}
},
}
数据
if(res.data.poolApplicationList && res.data.poolApplicationList.length > 0){
this.issunfa = false
this.list = []
this.currentPage = 1
this.loading = true;
this.allData = res.data.poolApplicationList
const startIndex = (this.currentPage - 1) * this.chunkSize;
const endIndex = startIndex + this.chunkSize;
this.list = [...this.list, ...this.allData.slice(startIndex, endIndex)];
this.currentPage++;
this.loading = false;
}else{
this.allData = []
this.list = []
this.issunfa = true
}
注释的为动画帧函数