nuxi add
將實體架構到您的 Nuxt 應用程式中。
終端機
npx nuxi add <TEMPLATE> <NAME> [--cwd=<directory>] [--logLevel=<silent|info|verbose>] [--force]
參數
參數 | 描述 |
---|---|
TEMPLATE | 指定要產生的模板(選項:<api|plugin|component|composable|middleware|layout|page>) |
NAME | 指定產生檔案的名稱 |
選項
選項 | 預設值 | 描述 |
---|---|---|
--cwd=<directory> | . | 指定工作目錄 |
--logLevel=<silent|info|verbose> | 指定建置時的記錄層級 | |
--force | false | 強制覆蓋已存在之檔案 |
修飾符
某些模板支援額外的修飾符標記,以便在其名稱中新增後綴 (例如 .client
或 .get
)。
終端機
# Generates `/plugins/sockets.client.ts`
npx nuxi add plugin sockets --client
nuxi add component
- 修飾符標記:
--mode client|server
或--client
或--server
終端機
# Generates `components/TheHeader.vue`
npx nuxi add component TheHeader
nuxi add composable
終端機
# Generates `composables/foo.ts`
npx nuxi add composable foo
nuxi add layout
終端機
# Generates `layouts/custom.vue`
npx nuxi add layout custom
nuxi add plugin
- 修飾符標記:
--mode client|server
或--client
或--server
終端機
# Generates `plugins/analytics.ts`
npx nuxi add plugin analytics
nuxi add page
終端機
# Generates `pages/about.vue`
npx nuxi add page about
終端機
# Generates `pages/category/[id].vue`
npx nuxi add page "category/[id]"
nuxi add middleware
- 修飾符標記:
--global
終端機
# Generates `middleware/auth.ts`
npx nuxi add middleware auth
nuxi add api
- 修飾符標記:
--method
(可以接受connect
、delete
、get
、head
、options
、patch
、post
、put
或trace
) 或您可以直接使用--get
、--post
等。
終端機
# Generates `server/api/hello.ts`
npx nuxi add api hello