data(){
return {
page:1,
categoryList:[],
isLoading:false//防止多次请求
}
},
mounted(){
this.scroll()
},
methods:{
scroll() {
window.addEventListener("scroll", ()=>{
// 距离底部200px时加载一次
let bottomOfWindow = document.documentElement.offsetHeight - document.documentElement.scrollTop - window.innerHeight <= 200;
if (bottomOfWindow && this.isLoading == false) {
this.isLoading = true
this.page++
render(this.page);//请求方法
}
})
},
}