pengzhanbo 7503c7fffe feat(theme): add Global Component Badge
添加全局组件 Badge
2022-05-03 19:21:42 +08:00

34 lines
904 B
TypeScript

import { defineClientAppEnhance } from '@vuepress/client'
import { h } from 'vue'
import Badge from './components/global/Badge.vue'
import { useScrollPromise } from './composables'
import './styles/index.scss'
export default defineClientAppEnhance(({ app, router }) => {
app.component('Badge', Badge)
app.component('NavbarSearch', () => {
const SearchComponent =
app.component('Docsearch') || app.component('SearchBox')
if (SearchComponent) {
return h(SearchComponent)
}
return null
})
app.component('Comment', (props) => {
const CommentService = app.component('CommentService')
if (CommentService) {
return h(CommentService, props)
}
return null
})
const scrollBehavior = router.options.scrollBehavior!
router.options.scrollBehavior = async (...args) => {
await useScrollPromise().wait()
return scrollBehavior(...args)
}
})