fix: 修复 Layout.vue SSR 构建警告 (document is not defined)
This commit is contained in:
parent
b717fdb076
commit
34ef95cdf4
@ -1,18 +1,26 @@
|
||||
<script setup>
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
import { useRoute } from 'vitepress'
|
||||
import { computed, watch, onUnmounted } from 'vue'
|
||||
import { computed, watch, onMounted, onUnmounted } from 'vue'
|
||||
import Home from './Home.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const isHome = computed(() => route.path === '/' || route.path === '/index.html')
|
||||
|
||||
watch(isHome, (val) => {
|
||||
document.documentElement.classList.toggle('home-layout', val)
|
||||
}, { immediate: true })
|
||||
function toggleHomeLayout(val) {
|
||||
if (typeof document !== 'undefined') {
|
||||
document.documentElement.classList.toggle('home-layout', val)
|
||||
}
|
||||
}
|
||||
|
||||
watch(isHome, toggleHomeLayout, { immediate: true })
|
||||
|
||||
onMounted(() => toggleHomeLayout(isHome.value))
|
||||
|
||||
onUnmounted(() => {
|
||||
document.documentElement.classList.remove('home-layout')
|
||||
if (typeof document !== 'undefined') {
|
||||
document.documentElement.classList.remove('home-layout')
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user