feat: add paginated tag loading

This commit is contained in:
Tim
2025-09-12 14:41:45 +08:00
parent c3758cafe8
commit b9a5e48d40
8 changed files with 143 additions and 39 deletions
+14 -1
View File
@@ -25,6 +25,8 @@ const props = defineProps({
rootMargin: { type: String, default: '200px 0px' },
/** 触发阈值 */
threshold: { type: Number, default: 0 },
/** 自定义 IntersectionObserver 根元素(默认为视口) */
root: { type: Object, default: null },
})
const isLoading = ref(false)
@@ -58,7 +60,11 @@ const startObserver = () => {
isLoading.value = false
}
},
{ root: null, rootMargin: props.rootMargin, threshold: props.threshold },
{
root: props.root || null,
rootMargin: props.rootMargin,
threshold: props.threshold,
},
)
if (sentinel.value) io.observe(sentinel.value)
}
@@ -76,6 +82,13 @@ watch(
},
)
watch(
() => props.root,
() => {
nextTick(startObserver)
},
)
/** 父组件可选择性调用,用于外部强制重置(一般直接用 :key 重建更简单) */
const reset = () => {
done.value = false