feat: built-in ClientOnly component

pull/183/head
Evan You 4 years ago
parent 9bd79e8de1
commit 8809d2dbfc

@ -0,0 +1,11 @@
import { ref, onMounted, defineComponent } from 'vue'
export const ClientOnly = defineComponent({
setup(_, { slots }) {
const show = ref(false)
onMounted(() => {
show.value = true
})
return () => (show.value && slots.default ? slots.default() : null)
}
})

@ -1,10 +1,10 @@
import { h } from 'vue'
import { defineComponent, h } from 'vue'
import { useRoute } from '../router'
export const Content = {
export const Content = defineComponent({
name: 'VitePressContent',
setup() {
const route = useRoute()
return () => (route.component ? h(route.component) : null)
}
}
})

@ -4,6 +4,7 @@ import { SiteDataRef } from './composables/siteData'
import { PageDataRef } from './composables/pageData'
import { Content } from './components/Content'
import Debug from './components/Debug.vue'
import { ClientOnly } from './components/ClientOnly'
export function mixinGlobalComputed(
app: App,
@ -68,6 +69,6 @@ export function mixinGlobalComponents(app: App) {
const isProd = process.env.NODE_ENV === 'production'
app.component('Content', Content)
app.component('ClientOnly', ClientOnly)
app.component('Debug', isProd ? () => null : Debug)
}

Loading…
Cancel
Save