fix(theme): 修复博客页组件过渡效果导致的SSR水合错误

This commit is contained in:
pengzhanbo 2024-03-25 13:26:57 +08:00
parent e3f79a8db6
commit c3d9a4e6de
2 changed files with 23 additions and 7 deletions

View File

@ -1,5 +1,6 @@
<script lang="ts" setup> <script lang="ts" setup>
import { usePageData } from 'vuepress/client' import { usePageData } from 'vuepress/client'
import { computed } from 'vue'
import type { PlumeThemePageData } from '../../../shared/index.js' import type { PlumeThemePageData } from '../../../shared/index.js'
import { useThemeLocaleData } from '../../composables/index.js' import { useThemeLocaleData } from '../../composables/index.js'
import TransitionFadeSlideY from '../TransitionFadeSlideY.vue' import TransitionFadeSlideY from '../TransitionFadeSlideY.vue'
@ -12,17 +13,32 @@ import BlogNav from './BlogNav.vue'
const theme = useThemeLocaleData() const theme = useThemeLocaleData()
const page = usePageData<PlumeThemePageData>() const page = usePageData<PlumeThemePageData>()
const com = {
PostList,
Tags,
Archives,
}
const type = computed(() => {
const type = page.value.type
if (type === 'blog-tags')
return 'Tags'
if (type === 'blog-archives')
return 'Archives'
return 'PostList'
})
</script> </script>
<template> <template>
<div class="blog-wrapper"> <div class="blog-wrapper">
<div class="blog-container" :class="{ 'no-avatar': !theme.avatar }"> <div class="blog-container" :class="{ 'no-avatar': !theme.avatar }">
<BlogNav v-if="!theme.avatar" is-local /> <BlogNav v-if="!theme.avatar" is-local />
<TransitionFadeSlideY> <TransitionFadeSlideY>
<PostList v-if="page.type === 'blog'" /> <component :is="com[type]" />
<Tags v-if="page.type === 'blog-tags'" />
<Archives v-if="page.type === 'blog-archives'" />
</TransitionFadeSlideY> </TransitionFadeSlideY>
<BlogAside /> <BlogAside />
<BlogExtract /> <BlogExtract />
</div> </div>

View File

@ -11,19 +11,19 @@ const avatar = computed(() => theme.value.avatar)
<template> <template>
<div v-if="avatar" class="avatar-profile"> <div v-if="avatar" class="avatar-profile">
<p v-if="avatar.url" :class="{ circle: avatar.circle }"> <p v-if="avatar.url" :class="{ circle: !!avatar.circle }">
<img :src="avatar.url" :alt="avatar.name"> <img :src="avatar.url" :alt="avatar.name">
</p> </p>
<div> <div class="avatar-info">
<h3>{{ avatar.name }}</h3> <h3>{{ avatar.name }}</h3>
<p v-if="avatar.description" v-html="avatar.description" /> <p v-if="avatar.description" v-html="avatar.description" />
<div v-if="avatar.location" class="avatar-location"> <div v-if="avatar.location" class="avatar-location">
<IconLocation /> <IconLocation />
<p v-html="avatar.location" /> <p v-if="avatar.location" v-html="avatar.location" />
</div> </div>
<div v-if="avatar.organization" class="avatar-organization"> <div v-if="avatar.organization" class="avatar-organization">
<IconOrganization /> <IconOrganization />
<p v-html="avatar.organization" /> <p v-if="avatar.organization" v-html="avatar.organization" />
</div> </div>
</div> </div>
<div v-if="theme.social" class="avatar-social"> <div v-if="theme.social" class="avatar-social">