本文介绍了vuepress-如何使用注册组件自定义组件目录'.vuepress/components'的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在vuepress中使用插件注册/组件添加组件的自定义目录,但这似乎是不可能的.

I tried to add custom directory of components in vuepress with plugin register/components but it seems not possible.

我尝试过

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

采用这种架构(我想选择组件"目录)

with this architecture (I want to select "components" directory)

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

But it seem doesn't work because the component is not recognized

我认为我在base-button.md中很好地编写了组件.

I think that I wrote well my component in my base-button.md

有人可以帮助我告诉我到达那里的步骤吗?

Is that someone could help me to tell me steps to get there?

非常感谢

推荐答案

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

You can register components globally in enhanceApp.js (which should be located in the /.vuepress/ folder) in the same way you register them in a Vue app.

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)
}

这篇关于vuepress-如何使用注册组件自定义组件目录'.vuepress/components'的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 03:53