分頁獲拉取下一頁數據 function loadNextPageData(self, callball) { if (window.IntersectionObserver) { const options = { root: null, threshold: 0 } const handleInt ...
分頁獲拉取下一頁數據
function loadNextPageData(self, callball) {
if (window.IntersectionObserver) {
const options = {
root: null,
threshold: 0
}
const handleIntersect = (entries, observer) => {
entries.forEach(async (entry) => {
if (entry.isIntersecting || entry.intersectionRatio || entry.isIntersecting === undefined) {
self.requesting = true
if (self.requesting && self.count > 0) {
self.requesting = false
self.pageIndex += 1
await callball(self.pageIndex)
self.requesting = true
} else {
self.isLoading = true // 不顯示
self.noMore = true // 載入到最後一頁無數據了
observer.unobserve(entry.target)
}
}
})
}
const observer = new IntersectionObserver(handleIntersect, options)
if (!self.isLoading) observer.observe(self.$refs.loading.$el.firstChild)
}
}