如何在Nuxt应用程序中仅删除一级组件前缀?

问题描述 投票:0回答:1

目录结构:

components
components/sections/
components/sections/profile
components/sections/profile/Sidebar.vue
components/sections/main/InformationSlider.vue

以下是这些组件的默认路径前缀,无需任何配置:

  1. <SectionsProfileSidebar />
  2. <SectionsMainInformationSlider />

就我而言,如何才能省略

Sections
前缀?这样组件的用法将如下所示:

  1. <ProfileSidebar />
  2. <MainInformationSlider />
vue.js nuxt.js nuxtjs3 nuxt3
1个回答
0
投票

要删除“部分”前缀,您可以修改您的

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目录中的组件添加前缀。

© www.soinside.com 2019 - 2024. All rights reserved.