element-plus/docs/.vitepress/vitepress/components/vp-content.vue
zouhang d8954f945e
chore: make eslint works in docs folder (#3582)
* chore: make eslints work in docs folder

* refactor(dev): improve eslint

* fix eslint issue

Co-authored-by: Kevin <sxzz@sxzz.moe>
Co-authored-by: jeremywuuuuu <15975785+JeremyWuuuuu@users.noreply.github.com>
2021-09-23 14:16:37 +08:00

47 lines
1.3 KiB
Vue

<script setup lang="ts">
import { computed, onUpdated, watch, ref, nextTick } from 'vue'
import nprogress from 'nprogress'
import { useData, useRoute } from 'vitepress'
import { useSidebar } from '../composables/sidebar'
import VPHeroContent from './vp-hero-content.vue'
import VPDocContent from './vp-doc-content.vue'
import VPNotFound from './vp-not-found.vue'
const { frontmatter } = useData()
const route = useRoute()
const isNotFound = computed(() => route.component === VPNotFound)
const isHeroPost = computed(() => frontmatter.value.page === true)
const { hasSidebar } = useSidebar()
const props = defineProps<{ isSidebarOpen: boolean }>()
const shouldUpdateProgress = ref(true)
watch(
() => props.isSidebarOpen,
(val) => {
// delay the flag update since watch is called before onUpdated
nextTick(() => {
shouldUpdateProgress.value = !val
})
}
)
onUpdated(() => {
if (shouldUpdateProgress.value) {
nprogress.done()
}
})
</script>
<template>
<main :class="{ 'page-content': true, 'has-sidebar': hasSidebar }">
<VPNotFound v-if="isNotFound" />
<VPHeroContent v-else-if="isHeroPost" />
<VPDocContent v-else>
<template #content-top><slot name="content-top" /></template>
<template #content-bottom><slot name="content-bottom" /></template>
</VPDocContent>
</main>
</template>