npx nuxt add <TEMPLATE> <NAME> [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--force]
| 参数 | 描述 |
|---|---|
TEMPLATE | 指定生成的模板类型(选项:<api|app|app-config|component|composable|error|layer|layout|middleware|module|page|plugin|server-middleware|server-plugin|server-route|server-util>) |
NAME | 指定生成文件的名称 |
| 选项 | 默认值 | 描述 |
|---|---|---|
--cwd=<directory> | . | 指定工作目录 |
--logLevel=<silent|info|verbose> | 指定构建时日志等级 | |
--force | false | 如果文件已存在,强制覆盖 |
修饰符:
某些模板支持附加修饰符标记,以在名称后添加后缀(比如 .client 或 .get)。
# 生成 `/plugins/sockets.client.ts`
npx nuxt add plugin sockets --client
nuxt add component--mode client|server 或 --client 或 --server# 生成 `components/TheHeader.vue`
npx nuxt add component TheHeader
nuxt add composable# 生成 `composables/foo.ts`
npx nuxt add composable foo
nuxt add layout# 生成 `layouts/custom.vue`
npx nuxt add layout custom
nuxt add plugin--mode client|server 或 --client 或 --server# 生成 `plugins/analytics.ts`
npx nuxt add plugin analytics
nuxt add page# 生成 `pages/about.vue`
npx nuxt add page about
# 生成 `pages/category/[id].vue`
npx nuxt add page "category/[id]"
nuxt add middleware--global# 生成 `middleware/auth.ts`
npx nuxt add middleware auth
nuxt add api--method (支持 connect, delete, get, head, options, patch, post, put 或 trace),或者你也可以直接使用 --get, --post 等。# 生成 `server/api/hello.ts`
npx nuxt add api hello
nuxt add layer# 生成 `layers/subscribe/nuxt.config.ts`
npx nuxt add layer subscribe