组件在带有模块的NUXT 3中自动导入
我想与nuxt一起使用模块(因此不是默认结构目录),类似的东西:
我不知道如何配置nuxt或我的模块以自动导入组件嵌套文件夹,例如card
文件夹。例如,planchoicecard.vue
组件是自动导入的,但不是nestedcomponent.vue
这是我的nuxt.config.js
:
import { defineNuxtConfig } from "nuxt";
export default defineNuxtConfig({
ssr: true,
ignore: ["node_modules/**/*"],
plugins: ["~/plugins/vue-i18n.client.ts"],
runtimeConfig: {
public: {
myapp: {
version: "1.7.8.2",
},
},
},
modules: ["./modules/Plans"],
build: {
postcss: {
postcssOptions: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
},
},
css: ["~/assets/css/tailwind.css"],
});
和配置的配置 : 计划
模块:
import path from "path";
import { defineNuxtModule } from "@nuxt/kit";
export default defineNuxtModule({
// Default configuration options for your module
defaults: {},
hooks: {
// ROUTES
"pages:extend"(pages) {
pages.push({
name: "user",
path: "/",
file: path.resolve(__dirname, "./views/PlanChoices.vue"),
});
},
// COMPONENTS
"components:dirs"(dirs) {
// Add ./components dir to the list
dirs.push({
path: path.resolve(__dirname, "./components"),
});
},
// COMPOSABLES
// "autoImports:dirs"(dirs) {
// dirs.push(path.resolve(__dirname, "./composables"));
// },
},
async setup(moduleOptions, nuxt) {
// -- Add your module logic here --
},
});
I want to use modules (so not the default structure directories) with Nuxt, something like that:
The problem is that I don't know how to configure Nuxt or my module to auto import the components in nested folders like the Card
folders. For example the PlanChoiceCard.vue
component is auto imported but not NestedComponent.vue
This is my nuxt.config.js
:
import { defineNuxtConfig } from "nuxt";
export default defineNuxtConfig({
ssr: true,
ignore: ["node_modules/**/*"],
plugins: ["~/plugins/vue-i18n.client.ts"],
runtimeConfig: {
public: {
myapp: {
version: "1.7.8.2",
},
},
},
modules: ["./modules/Plans"],
build: {
postcss: {
postcssOptions: {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
},
},
},
css: ["~/assets/css/tailwind.css"],
});
and the configuration of the Plans
module:
import path from "path";
import { defineNuxtModule } from "@nuxt/kit";
export default defineNuxtModule({
// Default configuration options for your module
defaults: {},
hooks: {
// ROUTES
"pages:extend"(pages) {
pages.push({
name: "user",
path: "/",
file: path.resolve(__dirname, "./views/PlanChoices.vue"),
});
},
// COMPONENTS
"components:dirs"(dirs) {
// Add ./components dir to the list
dirs.push({
path: path.resolve(__dirname, "./components"),
});
},
// COMPOSABLES
// "autoImports:dirs"(dirs) {
// dirs.push(path.resolve(__dirname, "./composables"));
// },
},
async setup(moduleOptions, nuxt) {
// -- Add your module logic here --
},
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是使与
nuxt.config.ts
中的相同:from /a/66336654/10805872
so:so:
so: ste:
使用前缀,您必须使用它,例如
模块/user/user/localeswitcher.vue
,as&code>< user -locale-switcher/>
没有前缀so
pathprefix:false
,您可以直接使用< locale-switcher/>
The answer was to make the same as in
nuxt.config.ts
:from https://stackoverflow.com/a/66336654/10805872
So:
become:
With the prefix you have to use it, for example a component in
modules/user/localeSwitcher.vue
, as<user-locale-switcher />
Without prefix so
pathPrefix: false
, you can use directly<locale-switcher />