Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dbff840

Browse files
feat: add DemoRender
1 parent 3cbac00 commit dbff840

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<ClientOnly>
3+
<div
4+
:style="{
5+
width: '100%',
6+
borderRadius: '8px',
7+
padding: '20px',
8+
backgroundColor: '#FFF',
9+
border: '1px solid lightgray',
10+
}"
11+
>
12+
<component :is="vueComponent" />
13+
</div>
14+
</ClientOnly>
15+
</template>
16+
17+
<script setup lang="ts">
18+
const props = defineProps<{
19+
component: string
20+
}>()
21+
22+
const vueComponent = (await import(`../code/${props.component}.vue`)).default
23+
</script>

‎site/.vitepress/components/code-demo.md

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
1-
<ClientOnly>
2-
<div
3-
:style="{
4-
width: '100%',
5-
borderRadius: '8px',
6-
padding: '20px',
7-
backgroundColor: '#FFF',
8-
border: '1px solid lightgray',
9-
}"
10-
>
11-
<component :is="component" />
12-
</div>
13-
</ClientOnly>
1+
<Suspense>
2+
<DemoRender :component="component" />
3+
</Suspense>
144

155
<ClientOnly>
166
<div :style="{ margin: '16px 0' }">
@@ -28,6 +18,7 @@
2818
import { ref } from 'vue'
2919
import { useData } from 'vitepress'
3020

21+
import DemoRender from './DemoRender.vue'
3122
import PlaygroundLink from './PlaygroundLink.vue'
3223
import { data as sourceCodeMap } from '../data/code.data'
3324
import { codeDemoI18n } from '../constants/i18n'

‎site/.vitepress/theme/index.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,9 @@ import '@wsfe/vue-tree/style.css'
77

88
export default {
99
extends: DefaultTheme,
10-
asyncenhanceApp({ app }) {
10+
enhanceApp({ app }) {
1111
// 注册自定义全局组件
1212
app.component('CodeDemo', CodeDemo)
1313
app.component('PlaygroundLink', PlaygroundLink)
14-
15-
const codeDemoComponents = import.meta.glob('../code/*.vue')
16-
17-
for (const path in codeDemoComponents) {
18-
const component = await codeDemoComponents[path]()
19-
const componentName = path.match(/^(?:.*\/)?(.+)\.vue$/)?.[1]
20-
if (componentName && component?.default) {
21-
app.component(componentName, component.default)
22-
}
23-
}
2414
}
2515
} satisfies Theme

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /