fix(docs): 为预览组件添加 clientOnly 配置并提供 ElementPlus 注入键

- 在 Markdown 配置中为 containerPreview 和 componentPreview 添加 clientOnly 选项
- 在主题增强中通过 app.provide 提供 ElementPlus 的 ID_INJECTION_KEY 和 ZINDEX_INJECTION_KEY
- 确保预览组件兼容客户端渲染环境
This commit is contained in:
“chenhuachun”
2026-08-23 18:50:41 +08:00
parent b29e8427cd
commit 4d3e4f0934
2 changed files with 6 additions and 2 deletions

View File

@@ -62,8 +62,8 @@ export default defineConfig({
},
markdown: {
config(md) {
md.use(containerPreview);
md.use(componentPreview);
md.use(containerPreview, { clientOnly: true });
md.use(componentPreview, { clientOnly: true });
}
},
outDir,

View File

@@ -4,6 +4,7 @@ import 'regenerator-runtime/runtime';
import { h, defineAsyncComponent } from 'vue';
import { type Theme } from 'vitepress';
import DefaultTheme from 'vitepress/theme';
import { ID_INJECTION_KEY, ZINDEX_INJECTION_KEY } from 'element-plus';
// @ts-ignore
import { ElementPlusContainer } from '@vitepress-demo-preview/component';
// import { ElMessageBox } from 'element-plus';
@@ -20,6 +21,9 @@ export default {
});
},
enhanceApp({ app, router, siteData }) {
app.provide(ID_INJECTION_KEY, { prefix: 0, current: 0 });
app.provide(ZINDEX_INJECTION_KEY, { current: 0 });
// app.component('demo-preview', ElementPlusContainer);
app.component(
'demo-preview',