@nuxt/docs 3.19.2 → 3.19.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +2 -2
- package/1.getting-started/02.installation.md +1 -0
- package/1.getting-started/03.configuration.md +29 -29
- package/1.getting-started/04.views.md +7 -7
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +55 -45
- package/1.getting-started/07.routing.md +12 -12
- package/1.getting-started/08.seo-meta.md +55 -42
- package/1.getting-started/09.transitions.md +47 -42
- package/1.getting-started/10.data-fetching.md +90 -67
- package/1.getting-started/11.state-management.md +22 -15
- package/1.getting-started/12.error-handling.md +11 -9
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +21 -15
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +9 -9
- package/1.getting-started/17.testing.md +43 -43
- package/1.getting-started/18.upgrade.md +58 -57
- package/2.guide/0.index.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.output.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.assets.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.components.md +41 -24
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.composables.md +11 -11
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.layouts.md +16 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.middleware.md +28 -22
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.pages.md +33 -31
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +34 -34
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.utils.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +5 -5
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app-config.md +12 -12
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.app.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +18 -18
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +10 -10
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +9 -9
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +21 -19
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +4 -4
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +15 -13
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +11 -11
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +80 -80
- package/2.guide/3.going-further/1.features.md +15 -15
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +11 -11
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +89 -87
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +5 -5
- package/2.guide/3.going-further/7.layers.md +61 -52
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +31 -31
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +12 -12
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +12 -12
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
- package/3.api/1.components/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +4 -1
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +4 -4
- package/3.api/1.components/3.nuxt-layout.md +11 -6
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +2 -2
- package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-async-data.md +17 -17
- package/3.api/2.composables/use-cookie.md +28 -20
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +55 -29
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +4 -4
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +2 -2
- package/3.api/2.composables/use-lazy-fetch.md +2 -2
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +19 -19
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +9 -7
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +2 -2
- package/3.api/2.composables/use-server-seo-meta.md +4 -4
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +9 -7
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +4 -4
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +1 -1
- package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
- package/3.api/3.utils/define-nuxt-component.md +5 -5
- package/3.api/3.utils/define-nuxt-plugin.md +12 -12
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +21 -21
- package/3.api/3.utils/define-route-rules.md +5 -5
- package/3.api/3.utils/navigate-to.md +10 -10
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +11 -6
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +4 -4
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +2 -1
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +4 -2
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +12 -12
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +7 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.plugins.md +6 -5
- package/3.api/6.advanced/1.hooks.md +2 -2
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +6 -6
- package/5.community/5.framework-contribution.md +3 -3
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +19 -16
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/2.configuration.md +22 -20
- package/7.migration/20.module-authors.md +6 -6
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +20 -17
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +23 -19
- package/7.migration/7.component-options.md +14 -14
- package/7.migration/8.runtime-config.md +6 -6
- package/package.json +1 -1
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "plugins"
|
|
3
3
|
description: "Nuxt has a plugins system to use Vue plugins and more at the creation of your Vue application."
|
|
4
4
|
head.title: "plugins/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-plugin
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Nuxt automatically reads the files in the `plugins/` directory and loads them at the creation of the Vue application.
|
|
@@ -30,23 +30,23 @@ Only files at the top level of the directory (or index files within any subdirec
|
|
|
30
30
|
|
|
31
31
|
Only `foo.ts` and `bar/index.ts` would be registered.
|
|
32
32
|
|
|
33
|
-
To add plugins in subdirectories, you can use the [`plugins`](/docs/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
|
|
33
|
+
To add plugins in subdirectories, you can use the [`plugins`](/docs/3.x/api/nuxt-config#plugins-1) option in `nuxt.config.ts`:
|
|
34
34
|
|
|
35
35
|
```ts twoslash [nuxt.config.ts]
|
|
36
36
|
export default defineNuxtConfig({
|
|
37
37
|
plugins: [
|
|
38
38
|
'~/plugins/bar/baz',
|
|
39
|
-
'~/plugins/bar/foz'
|
|
40
|
-
]
|
|
39
|
+
'~/plugins/bar/foz',
|
|
40
|
+
],
|
|
41
41
|
})
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Creating Plugins
|
|
45
45
|
|
|
46
|
-
The only argument passed to a plugin is [`nuxtApp`](/docs/api/composables/use-nuxt-app).
|
|
46
|
+
The only argument passed to a plugin is [`nuxtApp`](/docs/3.x/api/composables/use-nuxt-app).
|
|
47
47
|
|
|
48
48
|
```ts twoslash [plugins/hello.ts]
|
|
49
|
-
export default defineNuxtPlugin(nuxtApp => {
|
|
49
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
50
50
|
// Doing something with nuxtApp
|
|
51
51
|
})
|
|
52
52
|
```
|
|
@@ -64,15 +64,15 @@ export default defineNuxtPlugin({
|
|
|
64
64
|
},
|
|
65
65
|
hooks: {
|
|
66
66
|
// You can directly register Nuxt app runtime hooks here
|
|
67
|
-
'app:created'() {
|
|
67
|
+
'app:created' () {
|
|
68
68
|
const nuxtApp = useNuxtApp()
|
|
69
69
|
// do something in the hook
|
|
70
|
-
}
|
|
70
|
+
},
|
|
71
71
|
},
|
|
72
72
|
env: {
|
|
73
73
|
// Set this value to `false` if you don't want the plugin to run when rendering server-only or island components.
|
|
74
|
-
islands: true
|
|
75
|
-
}
|
|
74
|
+
islands: true,
|
|
75
|
+
},
|
|
76
76
|
})
|
|
77
77
|
```
|
|
78
78
|
|
|
@@ -114,7 +114,7 @@ export default defineNuxtPlugin({
|
|
|
114
114
|
parallel: true,
|
|
115
115
|
async setup (nuxtApp) {
|
|
116
116
|
// the next plugin will be executed immediately
|
|
117
|
-
}
|
|
117
|
+
},
|
|
118
118
|
})
|
|
119
119
|
```
|
|
120
120
|
|
|
@@ -128,13 +128,13 @@ export default defineNuxtPlugin({
|
|
|
128
128
|
dependsOn: ['my-plugin'],
|
|
129
129
|
async setup (nuxtApp) {
|
|
130
130
|
// this plugin will wait for the end of `my-plugin`'s execution before it runs
|
|
131
|
-
}
|
|
131
|
+
},
|
|
132
132
|
})
|
|
133
133
|
```
|
|
134
134
|
|
|
135
135
|
## Using Composables
|
|
136
136
|
|
|
137
|
-
You can use [composables](/docs/guide/directory-structure/composables) as well as [utils](/docs/guide/directory-structure/utils) within Nuxt plugins:
|
|
137
|
+
You can use [composables](/docs/3.x/guide/directory-structure/composables) as well as [utils](/docs/3.x/guide/directory-structure/utils) within Nuxt plugins:
|
|
138
138
|
|
|
139
139
|
```ts [plugins/hello.ts]
|
|
140
140
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
@@ -153,20 +153,20 @@ Plugins are called in order sequentially and before everything else. You might u
|
|
|
153
153
|
::important
|
|
154
154
|
**If a composable depends on the Vue.js lifecycle, it won't work.** :br
|
|
155
155
|
|
|
156
|
-
Normally, Vue.js composables are bound to the current component instance while plugins are only bound to [`nuxtApp`](/docs/api/composables/use-nuxt-app) instance.
|
|
156
|
+
Normally, Vue.js composables are bound to the current component instance while plugins are only bound to [`nuxtApp`](/docs/3.x/api/composables/use-nuxt-app) instance.
|
|
157
157
|
::
|
|
158
158
|
|
|
159
159
|
## Providing Helpers
|
|
160
160
|
|
|
161
|
-
If you would like to provide a helper on the [`NuxtApp`](/docs/api/composables/use-nuxt-app) instance, return it from the plugin under a `provide` key.
|
|
161
|
+
If you would like to provide a helper on the [`NuxtApp`](/docs/3.x/api/composables/use-nuxt-app) instance, return it from the plugin under a `provide` key.
|
|
162
162
|
|
|
163
163
|
::code-group
|
|
164
164
|
```ts twoslash [plugins/hello.ts]
|
|
165
165
|
export default defineNuxtPlugin(() => {
|
|
166
166
|
return {
|
|
167
167
|
provide: {
|
|
168
|
-
hello: (msg: string) => `Hello ${msg}
|
|
169
|
-
}
|
|
168
|
+
hello: (msg: string) => `Hello ${msg}!`,
|
|
169
|
+
},
|
|
170
170
|
}
|
|
171
171
|
})
|
|
172
172
|
```
|
|
@@ -176,10 +176,10 @@ export default defineNuxtPlugin({
|
|
|
176
176
|
setup () {
|
|
177
177
|
return {
|
|
178
178
|
provide: {
|
|
179
|
-
hello: (msg: string) => `Hello ${msg}
|
|
180
|
-
}
|
|
179
|
+
hello: (msg: string) => `Hello ${msg}!`,
|
|
180
|
+
},
|
|
181
181
|
}
|
|
182
|
-
}
|
|
182
|
+
},
|
|
183
183
|
})
|
|
184
184
|
```
|
|
185
185
|
::
|
|
@@ -200,7 +200,7 @@ const { $hello } = useNuxtApp()
|
|
|
200
200
|
```
|
|
201
201
|
|
|
202
202
|
::important
|
|
203
|
-
Note that we highly recommend using [`composables`](/docs/guide/directory-structure/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
|
|
203
|
+
Note that we highly recommend using [`composables`](/docs/3.x/guide/directory-structure/composables) instead of providing helpers to avoid polluting the global namespace and keep your main bundle entry small.
|
|
204
204
|
::
|
|
205
205
|
|
|
206
206
|
::warning
|
|
@@ -213,7 +213,7 @@ This is due to how Vue works with refs that aren't top-level to the template. Yo
|
|
|
213
213
|
If you return your helpers from the plugin, they will be typed automatically; you'll find them typed for the return of `useNuxtApp()` and within your templates.
|
|
214
214
|
|
|
215
215
|
::note
|
|
216
|
-
If you need to use a provided helper _within_ another plugin, you can call [`useNuxtApp()`](/docs/api/composables/use-nuxt-app) to get the typed version. But in general, this should be avoided unless you are certain of the plugins' order.
|
|
216
|
+
If you need to use a provided helper _within_ another plugin, you can call [`useNuxtApp()`](/docs/3.x/api/composables/use-nuxt-app) to get the typed version. But in general, this should be avoided unless you are certain of the plugins' order.
|
|
217
217
|
::
|
|
218
218
|
|
|
219
219
|
For advanced use-cases, you can declare the type of injected properties like this:
|
|
@@ -263,8 +263,8 @@ import VueGtag, { trackRouter } from 'vue-gtag-next'
|
|
|
263
263
|
export default defineNuxtPlugin((nuxtApp) => {
|
|
264
264
|
nuxtApp.vueApp.use(VueGtag, {
|
|
265
265
|
property: {
|
|
266
|
-
id: 'GA_MEASUREMENT_ID'
|
|
267
|
-
}
|
|
266
|
+
id: 'GA_MEASUREMENT_ID',
|
|
267
|
+
},
|
|
268
268
|
})
|
|
269
269
|
trackRouter(useRouter())
|
|
270
270
|
})
|
|
@@ -283,7 +283,7 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
283
283
|
getSSRProps (binding, vnode) {
|
|
284
284
|
// you can provide SSR-specific props here
|
|
285
285
|
return {}
|
|
286
|
-
}
|
|
286
|
+
},
|
|
287
287
|
})
|
|
288
288
|
})
|
|
289
289
|
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: "public"
|
|
3
3
|
description: "The public/ directory is used to serve your website's static assets."
|
|
4
4
|
head.title: "public/"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-public
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Files contained within the `public/` directory are served at the root and are not modified by the build process. This is suitable for files that have to keep their names (e.g. `robots.txt`) _or_ likely won't change (e.g. `favicon.ico`).
|
|
@@ -17,7 +17,7 @@ Files contained within the `public/` directory are served at the root and are no
|
|
|
17
17
|
```vue [app.vue]
|
|
18
18
|
<script setup lang="ts">
|
|
19
19
|
useSeoMeta({
|
|
20
|
-
ogImage: '/og-image.png'
|
|
20
|
+
ogImage: '/og-image.png',
|
|
21
21
|
})
|
|
22
22
|
</script>
|
|
23
23
|
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: server
|
|
3
3
|
head.title: 'server/'
|
|
4
4
|
description: The server/ directory is used to register API and server handlers to your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-server
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Nuxt automatically scans files inside these directories to register API and server handlers with Hot Module Replacement (HMR) support.
|
|
@@ -24,7 +24,7 @@ The handler can directly return JSON data, a `Promise`, or use `event.node.res.e
|
|
|
24
24
|
```ts twoslash [server/api/hello.ts]
|
|
25
25
|
export default defineEventHandler((event) => {
|
|
26
26
|
return {
|
|
27
|
-
hello: 'world'
|
|
27
|
+
hello: 'world',
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
```
|
|
@@ -58,7 +58,7 @@ export default defineEventHandler(() => 'Hello World!')
|
|
|
58
58
|
Given the example above, the `/hello` route will be accessible at <http://localhost:3000/hello>.
|
|
59
59
|
|
|
60
60
|
::note
|
|
61
|
-
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/guide/directory-structure/pages#dynamic-routes) do.
|
|
61
|
+
Note that currently server routes do not support the full functionality of dynamic routes as [pages](/docs/3.x/guide/directory-structure/pages#dynamic-routes) do.
|
|
62
62
|
::
|
|
63
63
|
|
|
64
64
|
## Server Middleware
|
|
@@ -115,9 +115,9 @@ For example, you can define a custom handler utility that wraps the original han
|
|
|
115
115
|
import type { EventHandler, EventHandlerRequest } from 'h3'
|
|
116
116
|
|
|
117
117
|
export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
|
|
118
|
-
handler: EventHandler<T, D
|
|
118
|
+
handler: EventHandler<T, D>,
|
|
119
119
|
): EventHandler<T, D> =>
|
|
120
|
-
defineEventHandler<T>(async event => {
|
|
120
|
+
defineEventHandler<T>(async (event) => {
|
|
121
121
|
try {
|
|
122
122
|
// do something before the route handler
|
|
123
123
|
const response = await handler(event)
|
|
@@ -144,7 +144,7 @@ To improve clarity within your IDE between the auto-imports from 'nitro' and 'vu
|
|
|
144
144
|
}
|
|
145
145
|
```
|
|
146
146
|
|
|
147
|
-
Currently, these values won't be respected when type checking ([`nuxt typecheck`](/docs/api/commands/typecheck)), but you should get better type hints in your IDE.
|
|
147
|
+
Currently, these values won't be respected when type checking ([`nuxt typecheck`](/docs/3.x/api/commands/typecheck)), but you should get better type hints in your IDE.
|
|
148
148
|
|
|
149
149
|
## Recipes
|
|
150
150
|
|
|
@@ -244,10 +244,10 @@ You can now universally call this API using:
|
|
|
244
244
|
|
|
245
245
|
```vue [app.vue]
|
|
246
246
|
<script setup lang="ts">
|
|
247
|
-
async function submit() {
|
|
247
|
+
async function submit () {
|
|
248
248
|
const { body } = await $fetch('/api/submit', {
|
|
249
249
|
method: 'post',
|
|
250
|
-
body: { test: 123 }
|
|
250
|
+
body: { test: 123 },
|
|
251
251
|
})
|
|
252
252
|
}
|
|
253
253
|
</script>
|
|
@@ -279,11 +279,11 @@ If no errors are thrown, a status code of `200 OK` will be returned.
|
|
|
279
279
|
|
|
280
280
|
Any uncaught errors will return a `500 Internal Server Error` HTTP Error.
|
|
281
281
|
|
|
282
|
-
To return other error codes, throw an exception with [`createError`](/docs/api/utils/create-error):
|
|
282
|
+
To return other error codes, throw an exception with [`createError`](/docs/3.x/api/utils/create-error):
|
|
283
283
|
|
|
284
284
|
```ts [server/api/validation/[id\\].ts]
|
|
285
285
|
export default defineEventHandler((event) => {
|
|
286
|
-
const id = parseInt(event.context.params.id) as number
|
|
286
|
+
const id = Number.parseInt(event.context.params.id) as number
|
|
287
287
|
|
|
288
288
|
if (!Number.isInteger(id)) {
|
|
289
289
|
throw createError({
|
|
@@ -297,7 +297,7 @@ export default defineEventHandler((event) => {
|
|
|
297
297
|
|
|
298
298
|
### Status Codes
|
|
299
299
|
|
|
300
|
-
To return other status codes, use the [`setResponseStatus`](/docs/api/utils/set-response-status) utility.
|
|
300
|
+
To return other status codes, use the [`setResponseStatus`](/docs/3.x/api/utils/set-response-status) utility.
|
|
301
301
|
|
|
302
302
|
For example, to return `202 Accepted`
|
|
303
303
|
|
|
@@ -316,8 +316,8 @@ export default defineEventHandler(async (event) => {
|
|
|
316
316
|
|
|
317
317
|
const repo = await $fetch('https://api.github.com/repos/nuxt/nuxt', {
|
|
318
318
|
headers: {
|
|
319
|
-
Authorization: `token ${config.githubToken}
|
|
320
|
-
}
|
|
319
|
+
Authorization: `token ${config.githubToken}`,
|
|
320
|
+
},
|
|
321
321
|
})
|
|
322
322
|
|
|
323
323
|
return repo
|
|
@@ -326,8 +326,8 @@ export default defineEventHandler(async (event) => {
|
|
|
326
326
|
```ts [nuxt.config.ts]
|
|
327
327
|
export default defineNuxtConfig({
|
|
328
328
|
runtimeConfig: {
|
|
329
|
-
githubToken: ''
|
|
330
|
-
}
|
|
329
|
+
githubToken: '',
|
|
330
|
+
},
|
|
331
331
|
})
|
|
332
332
|
```
|
|
333
333
|
```ini [.env]
|
|
@@ -336,7 +336,7 @@ NUXT_GITHUB_TOKEN='<my-super-token>'
|
|
|
336
336
|
::
|
|
337
337
|
|
|
338
338
|
::note
|
|
339
|
-
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
339
|
+
Giving the `event` as argument to `useRuntimeConfig` is optional, but it is recommended to pass it to get the runtime config overwritten by [environment variables](/docs/3.x/guide/going-further/runtime-config#environment-variables) at runtime for server routes.
|
|
340
340
|
::
|
|
341
341
|
|
|
342
342
|
### Request Cookies
|
|
@@ -373,8 +373,8 @@ The `event.waitUntil` method accepts a promise that will be awaited before the h
|
|
|
373
373
|
|
|
374
374
|
```ts [server/api/background-task.ts]
|
|
375
375
|
const timeConsumingBackgroundTask = async () => {
|
|
376
|
-
await new Promise(
|
|
377
|
-
}
|
|
376
|
+
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
377
|
+
}
|
|
378
378
|
|
|
379
379
|
export default eventHandler((event) => {
|
|
380
380
|
// schedule a background task without blocking the response
|
|
@@ -382,7 +382,7 @@ export default eventHandler((event) => {
|
|
|
382
382
|
|
|
383
383
|
// immediately send the response to the client
|
|
384
384
|
return 'done'
|
|
385
|
-
})
|
|
385
|
+
})
|
|
386
386
|
```
|
|
387
387
|
|
|
388
388
|
## Advanced Usage
|
|
@@ -398,7 +398,7 @@ This is an advanced option. Custom config can affect production deployments, as
|
|
|
398
398
|
```ts [nuxt.config.ts]
|
|
399
399
|
export default defineNuxtConfig({
|
|
400
400
|
// https://nitro.build/config
|
|
401
|
-
nitro: {}
|
|
401
|
+
nitro: {},
|
|
402
402
|
})
|
|
403
403
|
```
|
|
404
404
|
|
|
@@ -478,14 +478,14 @@ export default defineNuxtConfig({
|
|
|
478
478
|
driver: 'redis',
|
|
479
479
|
/* redis connector options */
|
|
480
480
|
port: 6379, // Redis port
|
|
481
|
-
host:
|
|
482
|
-
username:
|
|
483
|
-
password:
|
|
481
|
+
host: '127.0.0.1', // Redis host
|
|
482
|
+
username: '', // needs Redis >= 6
|
|
483
|
+
password: '',
|
|
484
484
|
db: 0, // Defaults to 0
|
|
485
|
-
tls: {} // tls/ssl
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
}
|
|
485
|
+
tls: {}, // tls/ssl
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
489
|
})
|
|
490
490
|
```
|
|
491
491
|
|
|
@@ -521,11 +521,11 @@ export default defineNitroPlugin(() => {
|
|
|
521
521
|
|
|
522
522
|
// Dynamically pass in credentials from runtime configuration, or other sources
|
|
523
523
|
const driver = redisDriver({
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
524
|
+
base: 'redis',
|
|
525
|
+
host: useRuntimeConfig().redis.host,
|
|
526
|
+
port: useRuntimeConfig().redis.port,
|
|
527
|
+
/* other redis connector options */
|
|
528
|
+
})
|
|
529
529
|
|
|
530
530
|
// Mount driver
|
|
531
531
|
storage.mount('redis', driver)
|
|
@@ -539,8 +539,8 @@ export default defineNuxtConfig({
|
|
|
539
539
|
host: '',
|
|
540
540
|
port: 0,
|
|
541
541
|
/* other redis connector options */
|
|
542
|
-
}
|
|
543
|
-
}
|
|
542
|
+
},
|
|
543
|
+
},
|
|
544
544
|
})
|
|
545
545
|
```
|
|
546
546
|
::
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: 'shared'
|
|
3
3
|
head.title: 'shared/'
|
|
4
4
|
description: 'Use the shared/ directory to share functionality between the Vue app and the Nitro server.'
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-shared
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
The `shared/` directory allows you to share code that can be used in both the Vue app and the Nitro server.
|
|
@@ -18,7 +18,7 @@ Code in the `shared/` directory cannot import any Vue or Nitro code.
|
|
|
18
18
|
::warning
|
|
19
19
|
Auto-imports are not enabled by default in Nuxt v3 to prevent breaking changes in existing projects.
|
|
20
20
|
|
|
21
|
-
To use these auto-imported utils and types, you must first [set `future.compatibilityVersion: 4` in your `nuxt.config.ts`](/docs/getting-started/upgrade#opting-in-to-nuxt-4).
|
|
21
|
+
To use these auto-imported utils and types, you must first [set `future.compatibilityVersion: 4` in your `nuxt.config.ts`](/docs/3.x/getting-started/upgrade#opting-in-to-nuxt-4).
|
|
22
22
|
::
|
|
23
23
|
|
|
24
24
|
:video-accordion{title="Watch a video from Vue School on sharing utils and types between app and server" videoId="nnAR-MO3q5M"}
|
|
@@ -41,7 +41,7 @@ export default function (input: string) {
|
|
|
41
41
|
}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
You can now use [auto-imported](/docs/guide/directory-structure/shared#auto-imports) utilities in your Nuxt app and `server/` directory.
|
|
44
|
+
You can now use [auto-imported](/docs/3.x/guide/directory-structure/shared#auto-imports) utilities in your Nuxt app and `server/` directory.
|
|
45
45
|
|
|
46
46
|
```vue [app.vue]
|
|
47
47
|
<script setup lang="ts">
|
|
@@ -58,7 +58,7 @@ const hello = capitalize('hello')
|
|
|
58
58
|
```ts [server/api/hello.get.ts]
|
|
59
59
|
export default defineEventHandler((event) => {
|
|
60
60
|
return {
|
|
61
|
-
hello: capitalize('hello')
|
|
61
|
+
hello: capitalize('hello'),
|
|
62
62
|
}
|
|
63
63
|
})
|
|
64
64
|
```
|
|
@@ -68,7 +68,7 @@ export default defineEventHandler((event) => {
|
|
|
68
68
|
Only files in the `shared/utils/` and `shared/types/` directories will be auto-imported. Files nested within subdirectories of these directories will not be auto-imported unless you add these directories to `imports.dirs` and `nitro.imports.dirs`.
|
|
69
69
|
|
|
70
70
|
::tip
|
|
71
|
-
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`composables/`](/docs/guide/directory-structure/composables) and [`utils/`](/docs/guide/directory-structure/utils) directories.
|
|
71
|
+
The way `shared/utils` and `shared/types` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/guide/directory-structure/composables) and [`utils/`](/docs/3.x/guide/directory-structure/utils) directories.
|
|
72
72
|
::
|
|
73
73
|
|
|
74
74
|
:read-more{to="/docs/guide/directory-structure/composables#how-files-are-scanned"}
|
|
@@ -83,7 +83,7 @@ The way `shared/utils` and `shared/types` auto-imports work and are scanned is i
|
|
|
83
83
|
-----| formatters
|
|
84
84
|
-------| upper.ts # Not auto-imported
|
|
85
85
|
---| types/
|
|
86
|
-
-----| bar.
|
|
86
|
+
-----| bar.ts # Auto-imported
|
|
87
87
|
```
|
|
88
88
|
|
|
89
89
|
Any other files you create in the `shared/` folder must be manually imported using the `#shared` alias (automatically configured by Nuxt):
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
title: 'utils'
|
|
3
3
|
head.title: 'utils/'
|
|
4
4
|
description: Use the utils/ directory to auto-import your utility functions throughout your application.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-folder-type-tools
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The main purpose of the [`utils/` directory](/docs/guide/directory-structure/utils) is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
|
|
8
|
+
The main purpose of the [`utils/` directory](/docs/3.x/guide/directory-structure/utils) is to allow a semantic distinction between your Vue composables and other auto-imported utility functions.
|
|
9
9
|
|
|
10
10
|
## Usage
|
|
11
11
|
|
|
@@ -14,7 +14,7 @@ The main purpose of the [`utils/` directory](/docs/guide/directory-structure/uti
|
|
|
14
14
|
```ts twoslash [utils/index.ts]
|
|
15
15
|
export const { format: formatNumber } = Intl.NumberFormat('en-GB', {
|
|
16
16
|
notation: 'compact',
|
|
17
|
-
maximumFractionDigits: 1
|
|
17
|
+
maximumFractionDigits: 1,
|
|
18
18
|
})
|
|
19
19
|
```
|
|
20
20
|
|
|
@@ -40,10 +40,10 @@ You can now use auto imported utility functions in `.js`, `.ts` and `.vue` files
|
|
|
40
40
|
:link-example{to="/docs/examples/features/auto-imports"}
|
|
41
41
|
|
|
42
42
|
::tip
|
|
43
|
-
The way `utils/` auto-imports work and are scanned is identical to the [`composables/`](/docs/guide/directory-structure/composables) directory.
|
|
43
|
+
The way `utils/` auto-imports work and are scanned is identical to the [`composables/`](/docs/3.x/guide/directory-structure/composables) directory.
|
|
44
44
|
::
|
|
45
45
|
|
|
46
46
|
::important
|
|
47
47
|
These utils are only available within the Vue part of your app. :br
|
|
48
|
-
Only `server/utils` are auto-imported in the [`server/`](/docs/guide/directory-structure/server#server-utilities) directory.
|
|
48
|
+
Only `server/utils` are auto-imported in the [`server/`](/docs/3.x/guide/directory-structure/server#server-utilities) directory.
|
|
49
49
|
::
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
title: ".env"
|
|
3
3
|
description: "A .env file specifies your build/dev-time environment variables."
|
|
4
4
|
head.title: ".env"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-dotenv
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
::important
|
|
9
|
-
This file should be added to your [`.gitignore`](/docs/guide/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
9
|
+
This file should be added to your [`.gitignore`](/docs/3.x/guide/directory-structure/gitignore) file to avoid pushing secrets to your repository.
|
|
10
10
|
::
|
|
11
11
|
|
|
12
12
|
## Dev, Build and Generate Time
|
|
13
13
|
|
|
14
|
-
Nuxt CLI has built-in [dotenv](https://github.com/motdotla/dotenv) support in development mode and when running [`nuxt build`](/docs/api/commands/build) and [`nuxt generate`](/docs/api/commands/generate).
|
|
14
|
+
Nuxt CLI has built-in [dotenv](https://github.com/motdotla/dotenv) support in development mode and when running [`nuxt build`](/docs/3.x/api/commands/build) and [`nuxt generate`](/docs/3.x/api/commands/generate).
|
|
15
15
|
|
|
16
16
|
In addition to any process environment variables, if you have a `.env` file in your project root directory, it will be automatically loaded **at dev, build and generate time**. Any environment variables set there will be accessible within your `nuxt.config` file and modules.
|
|
17
17
|
|
|
@@ -34,7 +34,7 @@ npx nuxt dev --dotenv .env.local
|
|
|
34
34
|
When updating `.env` in development mode, the Nuxt instance is automatically restarted to apply new values to the `process.env`.
|
|
35
35
|
|
|
36
36
|
::important
|
|
37
|
-
In your application code, you should use [Runtime Config](/docs/guide/going-further/runtime-config) instead of plain env variables.
|
|
37
|
+
In your application code, you should use [Runtime Config](/docs/3.x/guide/going-further/runtime-config) instead of plain env variables.
|
|
38
38
|
::
|
|
39
39
|
|
|
40
40
|
## Production
|
|
@@ -61,7 +61,7 @@ Since `.env` files are not used in production, you must explicitly set environme
|
|
|
61
61
|
|
|
62
62
|
## Production Preview
|
|
63
63
|
|
|
64
|
-
For local production preview purpose, we recommend using [`nuxt preview`](/docs/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
|
|
64
|
+
For local production preview purpose, we recommend using [`nuxt preview`](/docs/3.x/api/commands/preview) since using this command, the `.env` file will be loaded into `process.env` for convenience. Note that this command requires dependencies to be installed in the package directory.
|
|
65
65
|
|
|
66
66
|
Or you could pass the environment variables as arguments using the terminal. For example, on Linux or macOS:
|
|
67
67
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: ".gitignore"
|
|
3
3
|
description: "A .gitignore file specifies intentionally untracked files that git should ignore."
|
|
4
4
|
head.title: ".gitignore"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-git
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
A `.gitignore` file specifies intentionally untracked files that git should ignore.
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
title: .nuxtignore
|
|
3
3
|
head.title: '.nuxtignore'
|
|
4
4
|
description: The .nuxtignore file lets Nuxt ignore files in your project’s root directory during the build phase.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-nuxt
|
|
6
6
|
---
|
|
7
7
|
|
|
8
|
-
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/api/nuxt-config#rootdir)) during the build phase.
|
|
8
|
+
The `.nuxtignore` file tells Nuxt to ignore files in your project’s root directory ([`rootDir`](/docs/3.x/api/nuxt-config#rootdir)) during the build phase.
|
|
9
9
|
|
|
10
|
-
It is subject to the same specification as [`.gitignore`](/docs/guide/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
10
|
+
It is subject to the same specification as [`.gitignore`](/docs/3.x/guide/directory-structure/gitignore) and `.eslintignore` files, in which each line is a glob pattern indicating which files should be ignored.
|
|
11
11
|
|
|
12
12
|
::tip
|
|
13
|
-
You can also configure [`ignoreOptions`](/docs/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
13
|
+
You can also configure [`ignoreOptions`](/docs/3.x/api/nuxt-config#ignoreoptions), [`ignorePrefix`](/docs/3.x/api/nuxt-config#ignoreprefix) and [`ignore`](/docs/3.x/api/nuxt-config#ignore) in your `nuxt.config` file.
|
|
14
14
|
::
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
title: ".nuxtrc"
|
|
3
3
|
description: "The .nuxtrc file allows you to define nuxt configurations in a flat syntax."
|
|
4
4
|
head.title: ".nuxtrc"
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-nuxt
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
The `.nuxtrc` file can be used to configure Nuxt with a flat syntax. It is based on [`unjs/rc9`](https://github.com/unjs/rc9).
|
|
9
9
|
|
|
10
10
|
::tip
|
|
11
|
-
For more advanced configurations, use [`nuxt.config`](/docs/guide/directory-structure/nuxt-config).
|
|
11
|
+
For more advanced configurations, use [`nuxt.config`](/docs/3.x/guide/directory-structure/nuxt-config).
|
|
12
12
|
::
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
@@ -28,7 +28,7 @@ modules[]=nuxt-security
|
|
|
28
28
|
If present, the properties in the `nuxt.config` file will overwrite the properties in `.nuxtrc` file.
|
|
29
29
|
|
|
30
30
|
::note
|
|
31
|
-
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
31
|
+
Nuxt automatically adds a `setups` section to track module installation and upgrade state. This is used internally for [module lifecycle hooks](/docs/3.x/api/kit/modules#using-lifecycle-hooks-for-module-installation-and-upgrade) and should not be modified manually.
|
|
32
32
|
::
|
|
33
33
|
|
|
34
34
|
::read-more{to="/docs/api/configuration/nuxt-config"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
title: app.config.ts
|
|
3
3
|
head.title: 'app.config.ts'
|
|
4
4
|
description: Expose reactive configuration within your application with the App Config file.
|
|
5
|
-
navigation.icon: i-
|
|
5
|
+
navigation.icon: i-vscode-icons-file-type-light-config
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
Nuxt provides an `app.config` config file to expose reactive configuration within your application with the ability to update it at runtime within lifecycle or using a nuxt plugin and editing it with HMR (hot-module-replacement).
|
|
@@ -11,7 +11,7 @@ You can easily provide runtime app configuration using `app.config.ts` file. It
|
|
|
11
11
|
|
|
12
12
|
```ts twoslash [app.config.ts]
|
|
13
13
|
export default defineAppConfig({
|
|
14
|
-
foo: 'bar'
|
|
14
|
+
foo: 'bar',
|
|
15
15
|
})
|
|
16
16
|
```
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ Do not put any secret values inside `app.config` file. It is exposed to the user
|
|
|
20
20
|
::
|
|
21
21
|
|
|
22
22
|
::note
|
|
23
|
-
When configuring a custom [`srcDir`](/docs/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
23
|
+
When configuring a custom [`srcDir`](/docs/3.x/api/nuxt-config#srcdir), make sure to place the `app.config` file at the root of the new `srcDir` path.
|
|
24
24
|
::
|
|
25
25
|
|
|
26
26
|
## Usage
|
|
@@ -30,12 +30,12 @@ To expose config and environment variables to the rest of your app, you will nee
|
|
|
30
30
|
```ts twoslash [app.config.ts]
|
|
31
31
|
export default defineAppConfig({
|
|
32
32
|
theme: {
|
|
33
|
-
primaryColor: '#ababab'
|
|
34
|
-
}
|
|
33
|
+
primaryColor: '#ababab',
|
|
34
|
+
},
|
|
35
35
|
})
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/api/composables/use-app-config) composable.
|
|
38
|
+
We can now universally access `theme` both when server-rendering the page and in the browser using [`useAppConfig`](/docs/3.x/api/composables/use-app-config) composable.
|
|
39
39
|
|
|
40
40
|
```vue [pages/index.vue]
|
|
41
41
|
<script setup lang="ts">
|
|
@@ -45,7 +45,7 @@ console.log(appConfig.theme)
|
|
|
45
45
|
</script>
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
The [`updateAppConfig`](/docs/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
48
|
+
The [`updateAppConfig`](/docs/3.x/api/utils/update-app-config) utility can be used to update the `app.config` at runtime.
|
|
49
49
|
|
|
50
50
|
```vue [pages/index.vue]
|
|
51
51
|
<script setup>
|
|
@@ -90,7 +90,7 @@ export {}
|
|
|
90
90
|
|
|
91
91
|
### App Config Output
|
|
92
92
|
|
|
93
|
-
If you want to type the result of calling [`useAppConfig()`](/docs/api/composables/use-app-config), then you will want to extend `AppConfig`.
|
|
93
|
+
If you want to type the result of calling [`useAppConfig()`](/docs/3.x/api/composables/use-app-config), then you will want to extend `AppConfig`.
|
|
94
94
|
|
|
95
95
|
::warning
|
|
96
96
|
Be careful when typing `AppConfig` as you will overwrite the types Nuxt infers from your actually defined app config.
|
|
@@ -114,7 +114,7 @@ export {}
|
|
|
114
114
|
|
|
115
115
|
## Merging Strategy
|
|
116
116
|
|
|
117
|
-
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/getting-started/layers) of your application.
|
|
117
|
+
Nuxt uses a custom merging strategy for the `AppConfig` within [the layers](/docs/3.x/getting-started/layers) of your application.
|
|
118
118
|
|
|
119
119
|
This strategy is implemented using a [Function Merger](https://github.com/unjs/defu#function-merger), which allows defining a custom merging strategy for every key in `app.config` that has an array as value.
|
|
120
120
|
|
|
@@ -157,9 +157,9 @@ While it's possible to use Vite plugins in the Nitro config as a workaround, thi
|
|
|
157
157
|
export default defineNuxtConfig({
|
|
158
158
|
nitro: {
|
|
159
159
|
vite: {
|
|
160
|
-
plugins: [vue()]
|
|
161
|
-
}
|
|
162
|
-
}
|
|
160
|
+
plugins: [vue()],
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
163
|
})
|
|
164
164
|
```
|
|
165
165
|
|