mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 23:22:02 +00:00
chore: rename variable
This commit is contained in:
parent
0919a82a75
commit
f47b0d6c4e
@ -26,20 +26,20 @@ export const createLazyIOComponent = (componentLoader: Component) => {
|
|||||||
|
|
||||||
const nuxt = useNuxtApp()
|
const nuxt = useNuxtApp()
|
||||||
const instance = getCurrentInstance()!
|
const instance = getCurrentInstance()!
|
||||||
const isIntersecting = ref(false)
|
const hasIntersected = ref(false)
|
||||||
const el: Ref<Element | null> = ref(null)
|
const el: Ref<Element | null> = ref(null)
|
||||||
let unobserve: (() => void) | null = null
|
let unobserve: (() => void) | null = null
|
||||||
|
|
||||||
// todo can be refactored
|
// todo can be refactored
|
||||||
if (instance.vnode.el && nuxt.isHydrating) {
|
if (instance.vnode.el && nuxt.isHydrating) {
|
||||||
isIntersecting.value = elementIsVisibleInViewport(instance.vnode.el as Element)
|
hasIntersected.value = elementIsVisibleInViewport(instance.vnode.el as Element)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isIntersecting.value) {
|
if (!hasIntersected.value) {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
const observer = useIntersectionObserver(attrs.loader as Partial<IntersectionObserverInit> | undefined)
|
const observer = useIntersectionObserver(attrs.loader as Partial<IntersectionObserverInit> | undefined)
|
||||||
unobserve = observer!.observe(el.value as Element, () => {
|
unobserve = observer!.observe(el.value as Element, () => {
|
||||||
isIntersecting.value = true
|
hasIntersected.value = true
|
||||||
unobserve?.()
|
unobserve?.()
|
||||||
unobserve = null
|
unobserve = null
|
||||||
})
|
})
|
||||||
@ -51,7 +51,7 @@ export const createLazyIOComponent = (componentLoader: Component) => {
|
|||||||
})
|
})
|
||||||
return () => {
|
return () => {
|
||||||
return h('div', { ref: el }, [
|
return h('div', { ref: el }, [
|
||||||
isIntersecting.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1) : null,
|
hasIntersected.value ? h(componentLoader, attrs) : (instance.vnode.el && nuxt.isHydrating) ? createStaticVNode(getFragmentHTML(instance.vnode.el ?? null, true)?.join('') || '', 1) : null,
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user