目录结构:
components
components/sections/
components/sections/profile
components/sections/profile/Sidebar.vue
components/sections/main/InformationSlider.vue
以下是这些组件的默认路径前缀,无需任何配置:
<SectionsProfileSidebar />
<SectionsMainInformationSlider />
就我而言,如何才能省略
Sections
前缀?这样组件的用法将如下所示:
<ProfileSidebar />
<MainInformationSlider />
要删除“部分”前缀,您可以修改您的
nuxt.config.js
文件:
export default [
{
path: '-/components/sections/', // This will target 'sections'
pathPrefix: false, // Disable default prefix
prefix: 'custom',
extendComponentPrefix(componentPrefix, componentName) {
if (componentPrefix === 'custom) {
return componentName.replace(/([A-Z][a-z]+)([A-Z].*)/, '$1$2');
}
return componentName;
}
}
]
这会将 Nuxt 配置为不自动为sections目录中的组件添加前缀。