fix: ssg window

This commit is contained in:
YunYouJun
2022-04-17 17:16:48 +08:00
parent 3ae07a1073
commit 3ae7b0091c

View File

@@ -1,4 +1,4 @@
import { useElementBounding } from '@vueuse/core' import { isClient, useElementBounding } from '@vueuse/core'
import type { Ref } from 'vue' import type { Ref } from 'vue'
/** /**
@@ -10,11 +10,12 @@ export function useInvisibleElement(target: Ref<HTMLElement>) {
const { top } = useElementBounding(target) const { top } = useElementBounding(target)
const isVisible = computed(() => { const isVisible = computed(() => {
return window.scrollY < top.value return isClient ? window.scrollY < top.value : true
}) })
const show = () => { const show = () => {
window.scrollTo(0, top.value) if (isClient)
window.scrollTo(0, top.value)
} }
return { return {