BuptStEve / vuepress-plugin-demo-code

📝 Demo and code plugin for vuepress
https://buptsteve.github.io/vuepress-plugin-demo-code/
MIT License
125 stars 28 forks source link

如何渲染组件库内的自定义组件? #26

Closed ylc395 closed 4 years ago

ylc395 commented 4 years ago

作者你好,我仔细看了项目的文档,但还是不太清楚一些问题。我有一个自己开发的 Vue 组件库,组件代码都放在目录/components下(例如有一个组件components/MyComponent/index.vue)。VuePress 的docs目录也在同一项目中。我该如何使用这个插件,能让类似

::: demo
<MyComponent param="1"/>
:::

这样的 markdown 代码生效(即渲染出我的组件)呢?请赐教,多谢

BuptStEve commented 4 years ago

注册一下你的组件就行 https://v1.vuepress.vuejs.org/zh/guide/basic-config.html#%E5%BA%94%E7%94%A8%E7%BA%A7%E5%88%AB%E7%9A%84%E9%85%8D%E7%BD%AE

export default ({
  Vue, // VuePress 正在使用的 Vue 构造函数
  options, // 附加到根实例的一些选项
  router, // 当前应用的路由实例
  siteData // 站点元数据
}) => {
  // ...做一些其他的应用级别的优化

  // 在这里注册组件什么的 
  Vue.use(fooComponent)
}