写项目时,发现只有第一次滚动到底部才能加载新的数据,以后都不行,仔细检查代码以后发现没有问题
const scrollListenerHandler=()=>{
const clientHeight=document.documentElement.clientHeight
const scrollTop=document.documentElement.scrollTop
const scrollHeight=document.documentElement.scrollHeight
//console.log(scrollHeight,scrollTop,clientHeight)
if(scrollTop+clientHeight>=scrollHeight)
{
console.log("滚动到底部了")
homeStore.fetchHouseListData()
}
}
onMounted(()=>{
window.addEventListener("scroll",scrollListenerHandler)
})
于是console.log scrollHeight,scrollTop,clientHeight,发现第二次滚动到底部时总是差一点才会滚到相等,所以总是无法获取新数据。
667+4814=5481
令scrollHeight-1,就可以正常 获取了。