fix: fix hydration mismatch with the "last update" feature (#150)

pull/151/head
Kia King Ishii 4 years ago committed by GitHub
parent 0b181e7582
commit fc725e7295
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, computed } from 'vue' import { defineComponent, ref, computed, onMounted } from 'vue'
import { useSiteDataByRoute, usePageData } from 'vitepress' import { useSiteDataByRoute, usePageData } from 'vitepress'
export default defineComponent({ export default defineComponent({
@ -14,6 +14,8 @@ export default defineComponent({
const site = useSiteDataByRoute() const site = useSiteDataByRoute()
const page = usePageData() const page = usePageData()
const datetime = ref('')
const hasLastUpdated = computed(() => { const hasLastUpdated = computed(() => {
const lu = site.value.themeConfig.lastUpdated const lu = site.value.themeConfig.lastUpdated
@ -26,8 +28,8 @@ export default defineComponent({
return p === true ? 'Last Updated' : p return p === true ? 'Last Updated' : p
}) })
const datetime = computed(() => { onMounted(() => {
return new Date(page.value.lastUpdated).toLocaleString('en-US') datetime.value = new Date(page.value.lastUpdated).toLocaleString('en-US')
}) })
return { return {

Loading…
Cancel
Save