首页 文章

vuepress - 如何使用register-components自定义组件目录'.vuepress/components'的位置?

提问于
浏览
3

我尝试使用插件寄存器/组件在vuepress中添加组件的自定义目录,但似乎不可能 .

我试过了

module.exports = {
  title: 'Hello VuePress',
  description: 'Just playing around',
  plugins: [
   [
     'register-components',
     {
       componentDir: '../components'
     }
   ]
  ]
}

用这种架构(我想选择“组件”目录)

enter image description here

但它似乎不起作用,因为该组件未被识别

enter image description here

我认为我在base-button.md中写得很好

enter image description here

有人可以帮我告诉我到那儿的步骤吗?

非常感谢

1 回答

  • 4

    您可以在 enhanceApp.js (应该位于 /.vuepress/ 文件夹中)全局注册组件,方法与在Vue应用程序中注册它们的方式相同 .

    enhanceApp.js

    import BaseButton from '../../components/BaseButton'
    
    export default ({
      Vue, // the version of Vue being used in the VuePress app
      options, // the options for the root Vue instance
      router, // the router instance for the app
      siteData // site metadata
    }) => {
      Vue.component('BaseButton', BaseButton)
    }
    

相关问题