@nuxt/docs-nightly 4.1.3-29313386.edc02e27 → 4.1.3-29316215.910d159d
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 +4 -4
- package/1.getting-started/02.installation.md +1 -1
- package/1.getting-started/03.configuration.md +25 -25
- package/1.getting-started/04.views.md +3 -3
- package/1.getting-started/05.assets.md +9 -3
- package/1.getting-started/06.styling.md +53 -43
- package/1.getting-started/07.routing.md +9 -9
- package/1.getting-started/08.seo-meta.md +50 -37
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +61 -53
- package/1.getting-started/11.state-management.md +19 -12
- package/1.getting-started/12.error-handling.md +17 -15
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +19 -13
- package/1.getting-started/15.prerendering.md +28 -28
- package/1.getting-started/16.deployment.md +8 -8
- package/1.getting-started/17.testing.md +42 -42
- package/1.getting-started/18.upgrade.md +50 -68
- package/2.guide/0.index.md +5 -5
- package/2.guide/1.directory-structure/0.output.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.assets.md +1 -1
- package/2.guide/1.directory-structure/1.app/1.components.md +40 -23
- package/2.guide/1.directory-structure/1.app/1.composables.md +9 -9
- package/2.guide/1.directory-structure/1.app/1.layouts.md +12 -8
- package/2.guide/1.directory-structure/1.app/1.middleware.md +23 -17
- package/2.guide/1.directory-structure/1.app/1.pages.md +25 -23
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.app-config.md +7 -7
- package/2.guide/1.directory-structure/1.app/3.app.md +3 -3
- package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
- package/2.guide/1.directory-structure/1.content.md +4 -1
- package/2.guide/1.directory-structure/1.modules.md +5 -5
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +30 -30
- package/2.guide/1.directory-structure/1.shared.md +3 -3
- package/2.guide/1.directory-structure/2.env.md +3 -3
- package/2.guide/1.directory-structure/2.nuxtrc.md +1 -1
- package/2.guide/1.directory-structure/3.nuxt-config.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +15 -15
- package/2.guide/2.concepts/10.nuxt-lifecycle.md +7 -7
- package/2.guide/2.concepts/2.vuejs-development.md +9 -9
- package/2.guide/2.concepts/3.rendering.md +17 -15
- package/2.guide/2.concepts/4.server-engine.md +1 -1
- package/2.guide/2.concepts/5.modules.md +3 -3
- package/2.guide/2.concepts/7.esm.md +16 -14
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +238 -77
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +15 -15
- package/2.guide/3.going-further/10.runtime-config.md +8 -8
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +11 -11
- package/2.guide/3.going-further/3.modules.md +83 -81
- package/2.guide/3.going-further/4.kit.md +5 -5
- package/2.guide/3.going-further/6.nuxt-app.md +4 -4
- package/2.guide/3.going-further/7.layers.md +51 -42
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +19 -19
- package/2.guide/4.recipes/2.vite-plugin.md +3 -3
- package/2.guide/4.recipes/3.custom-usefetch.md +10 -10
- package/2.guide/4.recipes/4.sessions-and-authentication.md +34 -20
- package/2.guide/5.best-practices/performance.md +13 -13
- package/3.api/1.components/1.client-only.md +6 -3
- package/3.api/1.components/1.nuxt-client-fallback.md +10 -7
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
- 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 +13 -8
- package/3.api/1.components/4.nuxt-link.md +40 -20
- package/3.api/1.components/5.nuxt-loading-indicator.md +1 -1
- package/3.api/1.components/6.nuxt-error-boundary.md +12 -10
- package/3.api/2.composables/on-prehydrate.md +2 -2
- package/3.api/2.composables/use-app-config.md +1 -1
- package/3.api/2.composables/use-async-data.md +14 -14
- package/3.api/2.composables/use-cookie.md +27 -19
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +17 -17
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +3 -3
- package/3.api/2.composables/use-hydration.md +5 -5
- 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 +10 -10
- package/3.api/2.composables/use-nuxt-app.md +10 -10
- package/3.api/2.composables/use-nuxt-data.md +7 -7
- package/3.api/2.composables/use-preview-mode.md +12 -15
- package/3.api/2.composables/use-request-fetch.md +1 -1
- package/3.api/2.composables/use-request-headers.md +3 -3
- package/3.api/2.composables/use-response-header.md +7 -8
- package/3.api/2.composables/use-route-announcer.md +3 -3
- package/3.api/2.composables/use-router.md +6 -4
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +3 -3
- package/3.api/2.composables/use-server-seo-meta.md +3 -3
- package/3.api/2.composables/use-state.md +4 -4
- package/3.api/3.utils/$fetch.md +6 -4
- package/3.api/3.utils/abort-navigation.md +2 -2
- package/3.api/3.utils/add-route-middleware.md +3 -3
- package/3.api/3.utils/call-once.md +5 -5
- package/3.api/3.utils/clear-error.md +2 -2
- package/3.api/3.utils/clear-nuxt-data.md +2 -2
- package/3.api/3.utils/clear-nuxt-state.md +2 -2
- package/3.api/3.utils/create-error.md +2 -2
- 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 +2 -2
- package/3.api/3.utils/define-page-meta.md +16 -16
- 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/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +10 -5
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-response-status.md +2 -2
- package/3.api/3.utils/show-error.md +3 -3
- package/3.api/3.utils/update-app-config.md +3 -2
- package/3.api/4.commands/generate.md +1 -1
- package/3.api/4.commands/prepare.md +4 -0
- package/3.api/4.commands/typecheck.md +1 -1
- package/3.api/5.kit/1.modules.md +36 -36
- 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 +12 -12
- package/3.api/5.kit/5.components.md +5 -5
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +4 -4
- package/3.api/5.kit/8.layout.md +1 -1
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +1 -1
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +299 -864
- package/3.api/index.md +7 -7
- package/5.community/4.contribution.md +5 -5
- package/5.community/5.framework-contribution.md +1 -1
- package/6.bridge/1.overview.md +1 -1
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +2 -2
- package/6.bridge/3.bridge-composition-api.md +4 -4
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +12 -9
- package/6.bridge/6.meta.md +15 -14
- package/6.bridge/8.nitro.md +2 -2
- package/6.bridge/9.vite.md +3 -3
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +18 -16
- package/7.migration/20.module-authors.md +1 -1
- package/7.migration/4.meta.md +18 -15
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +20 -16
- package/7.migration/7.component-options.md +7 -7
- package/7.migration/8.runtime-config.md +4 -4
- package/package.json +1 -1
|
@@ -186,8 +186,8 @@ export default defineNuxtConfig({
|
|
|
186
186
|
srcDir: '.',
|
|
187
187
|
// This specifies the directory prefix for `router.options.ts` and `spa-loading-template.html`
|
|
188
188
|
dir: {
|
|
189
|
-
app: 'app'
|
|
190
|
-
}
|
|
189
|
+
app: 'app',
|
|
190
|
+
},
|
|
191
191
|
})
|
|
192
192
|
```
|
|
193
193
|
|
|
@@ -224,14 +224,14 @@ These changes have been made to improve memory usage and increase consistency wi
|
|
|
224
224
|
It may be beneficial to extract any calls to `useAsyncData` that share an explicit key (and have custom options) into their own composable:
|
|
225
225
|
|
|
226
226
|
```ts [app/composables/useUserData.ts]
|
|
227
|
-
export function useUserData(userId: string) {
|
|
227
|
+
export function useUserData (userId: string) {
|
|
228
228
|
return useAsyncData(
|
|
229
229
|
`user-${userId}`,
|
|
230
230
|
() => fetchUser(userId),
|
|
231
|
-
{
|
|
231
|
+
{
|
|
232
232
|
deep: true,
|
|
233
|
-
transform:
|
|
234
|
-
}
|
|
233
|
+
transform: user => ({ ...user, lastAccessed: new Date() }),
|
|
234
|
+
},
|
|
235
235
|
)
|
|
236
236
|
}
|
|
237
237
|
```
|
|
@@ -260,8 +260,8 @@ Alternatively, for now, you can disable this behaviour with:
|
|
|
260
260
|
export default defineNuxtConfig({
|
|
261
261
|
experimental: {
|
|
262
262
|
granularCachedData: false,
|
|
263
|
-
purgeCachedData: false
|
|
264
|
-
}
|
|
263
|
+
purgeCachedData: false,
|
|
264
|
+
},
|
|
265
265
|
})
|
|
266
266
|
```
|
|
267
267
|
|
|
@@ -303,18 +303,18 @@ Example of the new correct order:
|
|
|
303
303
|
```ts
|
|
304
304
|
// Layer: my-layer/nuxt.config.ts
|
|
305
305
|
export default defineNuxtConfig({
|
|
306
|
-
modules: ['layer-module-1', 'layer-module-2']
|
|
306
|
+
modules: ['layer-module-1', 'layer-module-2'],
|
|
307
307
|
})
|
|
308
308
|
|
|
309
309
|
// Project: nuxt.config.ts
|
|
310
310
|
export default defineNuxtConfig({
|
|
311
311
|
extends: ['./my-layer'],
|
|
312
|
-
modules: ['project-module-1', 'project-module-2']
|
|
312
|
+
modules: ['project-module-1', 'project-module-2'],
|
|
313
313
|
})
|
|
314
314
|
|
|
315
315
|
// Loading order (corrected):
|
|
316
316
|
// 1. layer-module-1
|
|
317
|
-
// 2. layer-module-2
|
|
317
|
+
// 2. layer-module-2
|
|
318
318
|
// 3. project-module-1 (can override layer modules)
|
|
319
319
|
// 4. project-module-2 (can override layer modules)
|
|
320
320
|
```
|
|
@@ -380,8 +380,8 @@ Alternatively, for now, you can disable this behaviour with:
|
|
|
380
380
|
```ts twoslash [nuxt.config.ts]
|
|
381
381
|
export default defineNuxtConfig({
|
|
382
382
|
experimental: {
|
|
383
|
-
normalizeComponentNames: false
|
|
384
|
-
}
|
|
383
|
+
normalizeComponentNames: false,
|
|
384
|
+
},
|
|
385
385
|
})
|
|
386
386
|
```
|
|
387
387
|
|
|
@@ -420,14 +420,14 @@ useHead({
|
|
|
420
420
|
* If you're using [Template Params](https://unhead.unjs.io/docs/head/guides/plugins/template-params) or [Alias Tag Sorting](https://unhead.unjs.io/docs/head/guides/plugins/alias-sorting), you will need to explicitly opt in to these features now.
|
|
421
421
|
|
|
422
422
|
```ts
|
|
423
|
-
import {
|
|
423
|
+
import { AliasSortingPlugin, TemplateParamsPlugin } from '@unhead/vue/plugins'
|
|
424
424
|
|
|
425
425
|
export default defineNuxtPlugin({
|
|
426
|
-
setup() {
|
|
426
|
+
setup () {
|
|
427
427
|
const unhead = injectHead()
|
|
428
428
|
unhead.use(TemplateParamsPlugin)
|
|
429
429
|
unhead.use(AliasSortingPlugin)
|
|
430
|
-
}
|
|
430
|
+
},
|
|
431
431
|
})
|
|
432
432
|
```
|
|
433
433
|
|
|
@@ -444,7 +444,7 @@ If you still have issues you may revert to the v1 behavior by enabling the `head
|
|
|
444
444
|
export default defineNuxtConfig({
|
|
445
445
|
unhead: {
|
|
446
446
|
legacy: true,
|
|
447
|
-
}
|
|
447
|
+
},
|
|
448
448
|
})
|
|
449
449
|
```
|
|
450
450
|
|
|
@@ -483,7 +483,7 @@ Alternatively, you can revert to the previous behaviour with:
|
|
|
483
483
|
export default defineNuxtConfig({
|
|
484
484
|
experimental: {
|
|
485
485
|
spaLoadingTemplateLocation: 'within',
|
|
486
|
-
}
|
|
486
|
+
},
|
|
487
487
|
})
|
|
488
488
|
```
|
|
489
489
|
|
|
@@ -527,8 +527,8 @@ This feature is fully configurable and you can revert to the previous behavior b
|
|
|
527
527
|
```ts twoslash [nuxt.config.ts]
|
|
528
528
|
export default defineNuxtConfig({
|
|
529
529
|
features: {
|
|
530
|
-
inlineStyles: true
|
|
531
|
-
}
|
|
530
|
+
inlineStyles: true,
|
|
531
|
+
},
|
|
532
532
|
})
|
|
533
533
|
```
|
|
534
534
|
|
|
@@ -566,8 +566,8 @@ Alternatively, you can revert to the previous behaviour with:
|
|
|
566
566
|
```ts twoslash [nuxt.config.ts]
|
|
567
567
|
export default defineNuxtConfig({
|
|
568
568
|
experimental: {
|
|
569
|
-
scanPageMeta: true
|
|
570
|
-
}
|
|
569
|
+
scanPageMeta: true,
|
|
570
|
+
},
|
|
571
571
|
})
|
|
572
572
|
```
|
|
573
573
|
|
|
@@ -607,8 +607,8 @@ Alternatively, you can disable this feature with:
|
|
|
607
607
|
```ts twoslash [nuxt.config.ts]
|
|
608
608
|
export default defineNuxtConfig({
|
|
609
609
|
experimental: {
|
|
610
|
-
sharedPrerenderData: false
|
|
611
|
-
}
|
|
610
|
+
sharedPrerenderData: false,
|
|
611
|
+
},
|
|
612
612
|
})
|
|
613
613
|
```
|
|
614
614
|
|
|
@@ -632,24 +632,6 @@ If you were checking if `data.value` or `error.value` were `null`, you can updat
|
|
|
632
632
|
You can automate this step by running `npx codemod@latest nuxt/4/default-data-error-value`
|
|
633
633
|
::
|
|
634
634
|
|
|
635
|
-
If you encounter any issues you can revert back to the previous behavior with:
|
|
636
|
-
|
|
637
|
-
```ts twoslash [nuxt.config.ts]
|
|
638
|
-
// @errors: 2353
|
|
639
|
-
export default defineNuxtConfig({
|
|
640
|
-
experimental: {
|
|
641
|
-
defaults: {
|
|
642
|
-
useAsyncData: {
|
|
643
|
-
value: 'null',
|
|
644
|
-
errorValue: 'null'
|
|
645
|
-
}
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
})
|
|
649
|
-
```
|
|
650
|
-
|
|
651
|
-
Please report an issue if you are doing this, as we do not plan to keep this as configurable.
|
|
652
|
-
|
|
653
635
|
### Removal of deprecated `boolean` values for `dedupe` option when calling `refresh` in `useAsyncData` and `useFetch`
|
|
654
636
|
|
|
655
637
|
🚦 **Impact Level**: Minimal
|
|
@@ -660,7 +642,7 @@ Previously it was possible to pass `dedupe: boolean` to `refresh`. These were al
|
|
|
660
642
|
|
|
661
643
|
```ts twoslash [app/app.vue]
|
|
662
644
|
// @errors: 2322
|
|
663
|
-
const { refresh } = await useAsyncData(
|
|
645
|
+
const { refresh } = await useAsyncData(() => Promise.resolve({ message: 'Hello, Nuxt!' }))
|
|
664
646
|
|
|
665
647
|
async function refreshData () {
|
|
666
648
|
await refresh({ dedupe: true })
|
|
@@ -748,8 +730,8 @@ Alternatively, you can temporarily revert to the previous behavior with:
|
|
|
748
730
|
```ts twoslash [nuxt.config.ts]
|
|
749
731
|
export default defineNuxtConfig({
|
|
750
732
|
experimental: {
|
|
751
|
-
pendingWhenIdle: true
|
|
752
|
-
}
|
|
733
|
+
pendingWhenIdle: true,
|
|
734
|
+
},
|
|
753
735
|
})
|
|
754
736
|
```
|
|
755
737
|
|
|
@@ -788,8 +770,8 @@ To opt out of this behavior:
|
|
|
788
770
|
// Or globally in your Nuxt config
|
|
789
771
|
export default defineNuxtConfig({
|
|
790
772
|
experimental: {
|
|
791
|
-
alwaysRunFetchOnKeyChange: true
|
|
792
|
-
}
|
|
773
|
+
alwaysRunFetchOnKeyChange: true,
|
|
774
|
+
},
|
|
793
775
|
})
|
|
794
776
|
```
|
|
795
777
|
|
|
@@ -822,10 +804,10 @@ In most cases, no migration steps are required, but if you rely on the reactivit
|
|
|
822
804
|
experimental: {
|
|
823
805
|
defaults: {
|
|
824
806
|
useAsyncData: {
|
|
825
|
-
deep: true
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
807
|
+
deep: true,
|
|
808
|
+
},
|
|
809
|
+
},
|
|
810
|
+
},
|
|
829
811
|
})
|
|
830
812
|
```
|
|
831
813
|
|
|
@@ -904,10 +886,10 @@ Probably no migration is necessary but if you wish to revert to previous behavio
|
|
|
904
886
|
```ts
|
|
905
887
|
export default defineNuxtConfig({
|
|
906
888
|
hooks: {
|
|
907
|
-
'app:resolve'(app) {
|
|
889
|
+
'app:resolve' (app) {
|
|
908
890
|
app.middleware = app.middleware.filter(mw => !/\/index\.[^/]+$/.test(mw.path))
|
|
909
|
-
}
|
|
910
|
-
}
|
|
891
|
+
},
|
|
892
|
+
},
|
|
911
893
|
})
|
|
912
894
|
```
|
|
913
895
|
|
|
@@ -957,7 +939,7 @@ Finally, if you are using the template utilities (`serialize`, `importName`, `im
|
|
|
957
939
|
```ts
|
|
958
940
|
import { genDynamicImport, genImport, genSafeVariableName } from 'knitwork'
|
|
959
941
|
|
|
960
|
-
const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"{(.+)}"(?=,?$)/gm, r => JSON.parse(r).replace(
|
|
942
|
+
const serialize = (data: any) => JSON.stringify(data, null, 2).replace(/"\{(.+)\}"(?=,?$)/gm, r => JSON.parse(r).replace(/^\{(.*)\}$/, '$1'))
|
|
961
943
|
|
|
962
944
|
const importSources = (sources: string | string[], { lazy = false } = {}) => {
|
|
963
945
|
return toArray(sources).map((src) => {
|
|
@@ -1002,10 +984,10 @@ There are two approaches:
|
|
|
1002
984
|
typescript: {
|
|
1003
985
|
tsConfig: {
|
|
1004
986
|
compilerOptions: {
|
|
1005
|
-
noUncheckedIndexedAccess: false
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
}
|
|
987
|
+
noUncheckedIndexedAccess: false,
|
|
988
|
+
},
|
|
989
|
+
},
|
|
990
|
+
},
|
|
1009
991
|
})
|
|
1010
992
|
```
|
|
1011
993
|
|
|
@@ -1090,16 +1072,16 @@ However, to take advantage of improved type checking, you can opt in to the new
|
|
|
1090
1072
|
// Customize app/server TypeScript config
|
|
1091
1073
|
tsConfig: {
|
|
1092
1074
|
compilerOptions: {
|
|
1093
|
-
strict: true
|
|
1094
|
-
}
|
|
1075
|
+
strict: true,
|
|
1076
|
+
},
|
|
1095
1077
|
},
|
|
1096
|
-
// Customize build-time TypeScript config
|
|
1078
|
+
// Customize build-time TypeScript config
|
|
1097
1079
|
nodeTsConfig: {
|
|
1098
1080
|
compilerOptions: {
|
|
1099
|
-
strict: true
|
|
1100
|
-
}
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1081
|
+
strict: true,
|
|
1082
|
+
},
|
|
1083
|
+
},
|
|
1084
|
+
},
|
|
1103
1085
|
})
|
|
1104
1086
|
```
|
|
1105
1087
|
|
|
@@ -1195,7 +1177,7 @@ Static sites | ✅ | ✅ | ✅
|
|
|
1195
1177
|
|
|
1196
1178
|
The migration guide provides a step-by-step comparison of Nuxt 2 features to Nuxt 3+ features and guidance to adapt your current application.
|
|
1197
1179
|
|
|
1198
|
-
::read-more{to="/docs/migration/overview"}
|
|
1180
|
+
::read-more{to="/docs/4.x/migration/overview"}
|
|
1199
1181
|
Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
1200
1182
|
::
|
|
1201
1183
|
|
|
@@ -1203,6 +1185,6 @@ Check out the **guide to migrating from Nuxt 2 to Nuxt 3**.
|
|
|
1203
1185
|
|
|
1204
1186
|
If you prefer to progressively migrate your Nuxt 2 application to Nuxt 3, you can use Nuxt Bridge. Nuxt Bridge is a compatibility layer that allows you to use Nuxt 3+ features in Nuxt 2 with an opt-in mechanism.
|
|
1205
1187
|
|
|
1206
|
-
::read-more{to="/docs/bridge/overview"}
|
|
1188
|
+
::read-more{to="/docs/4.x/bridge/overview"}
|
|
1207
1189
|
**Migrate from Nuxt 2 to Nuxt Bridge**
|
|
1208
1190
|
::
|
package/2.guide/0.index.md
CHANGED
|
@@ -7,19 +7,19 @@ surround: false
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
::card-group{class="sm:grid-cols-1"}
|
|
10
|
-
::card{icon="i-lucide-folders" title="Directory Structure" to="/docs/guide/directory-structure"}
|
|
10
|
+
::card{icon="i-lucide-folders" title="Directory Structure" to="/docs/4.x/guide/directory-structure"}
|
|
11
11
|
Learn about Nuxt directory structure and what benefits each directory or file offers.
|
|
12
12
|
::
|
|
13
|
-
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/guide/concepts"}
|
|
13
|
+
::card{icon="i-lucide-medal" title="Key Concepts" to="/docs/4.x/guide/concepts"}
|
|
14
14
|
Discover the main concepts behind Nuxt, from auto-import, hybrid rendering to its TypeScript support.
|
|
15
15
|
::
|
|
16
|
-
::card{icon="i-lucide-star" title="Going Further" to="/docs/guide/going-further"}
|
|
16
|
+
::card{icon="i-lucide-star" title="Going Further" to="/docs/4.x/guide/going-further"}
|
|
17
17
|
Master Nuxt with advanced concepts like experimental features, hooks, modules, and more.
|
|
18
18
|
::
|
|
19
|
-
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/guide/recipes"}
|
|
19
|
+
::card{icon="i-lucide-book-open" title="Recipes" to="/docs/4.x/guide/recipes"}
|
|
20
20
|
Find solutions to common problems and learn how to implement them in your Nuxt project.
|
|
21
21
|
::
|
|
22
|
-
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/guide/best-practices"}
|
|
22
|
+
::card{icon="i-lucide-square-check" title="Best Practices" to="/docs/4.x/guide/best-practices"}
|
|
23
23
|
Learn about best practices when developing with Nuxt
|
|
24
24
|
::
|
|
25
25
|
::
|
|
@@ -11,7 +11,7 @@ This directory should be added to your [`.gitignore`](/docs/4.x/guide/directory-
|
|
|
11
11
|
|
|
12
12
|
Use this directory to deploy your Nuxt application to production.
|
|
13
13
|
|
|
14
|
-
:read-more{to="/docs/getting-started/deployment"}
|
|
14
|
+
:read-more{to="/docs/4.x/getting-started/deployment"}
|
|
15
15
|
|
|
16
16
|
::warning
|
|
17
17
|
You should not touch any files inside since the whole directory will be re-created when running [`nuxt build`](/docs/4.x/api/commands/build).
|
|
@@ -13,4 +13,4 @@ The directory usually contains the following types of files:
|
|
|
13
13
|
|
|
14
14
|
If you want to serve assets from the server, we recommend taking a look at the [`public/`](/docs/4.x/guide/directory-structure/public) directory.
|
|
15
15
|
|
|
16
|
-
:read-more{to="/docs/getting-started/assets"}
|
|
16
|
+
:read-more{to="/docs/4.x/getting-started/assets"}
|
|
@@ -54,7 +54,7 @@ export default defineNuxtConfig({
|
|
|
54
54
|
pathPrefix: false, // [!code ++]
|
|
55
55
|
},
|
|
56
56
|
],
|
|
57
|
-
})
|
|
57
|
+
})
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
This registers the components using the same strategy as used in Nuxt 2. For example, `~/components/Some/MyComponent.vue` will be usable as `<MyComponent>` and not `<SomeMyComponent>`.
|
|
@@ -116,7 +116,12 @@ const show = ref(false)
|
|
|
116
116
|
<div>
|
|
117
117
|
<h1>Mountains</h1>
|
|
118
118
|
<LazyMountainsList v-if="show" />
|
|
119
|
-
<button
|
|
119
|
+
<button
|
|
120
|
+
v-if="!show"
|
|
121
|
+
@click="show = true"
|
|
122
|
+
>
|
|
123
|
+
Show List
|
|
124
|
+
</button>
|
|
120
125
|
</div>
|
|
121
126
|
</template>
|
|
122
127
|
```
|
|
@@ -235,9 +240,10 @@ Hydrates the component based on a boolean condition.
|
|
|
235
240
|
<LazyMyComponent :hydrate-when="isReady" />
|
|
236
241
|
</div>
|
|
237
242
|
</template>
|
|
243
|
+
|
|
238
244
|
<script setup lang="ts">
|
|
239
245
|
const isReady = ref(false)
|
|
240
|
-
function myFunction() {
|
|
246
|
+
function myFunction () {
|
|
241
247
|
// trigger custom hydration strategy...
|
|
242
248
|
isReady.value = true
|
|
243
249
|
}
|
|
@@ -263,13 +269,16 @@ All delayed hydration components emit a `@hydrated` event when they are hydrated
|
|
|
263
269
|
```vue [app/pages/index.vue]
|
|
264
270
|
<template>
|
|
265
271
|
<div>
|
|
266
|
-
<LazyMyComponent
|
|
272
|
+
<LazyMyComponent
|
|
273
|
+
hydrate-on-visible
|
|
274
|
+
@hydrated="onHydrate"
|
|
275
|
+
/>
|
|
267
276
|
</div>
|
|
268
277
|
</template>
|
|
269
278
|
|
|
270
279
|
<script setup lang="ts">
|
|
271
|
-
function onHydrate() {
|
|
272
|
-
console.log(
|
|
280
|
+
function onHydrate () {
|
|
281
|
+
console.log('Component has been hydrated!')
|
|
273
282
|
}
|
|
274
283
|
</script>
|
|
275
284
|
```
|
|
@@ -297,7 +306,7 @@ You can also explicitly import components from `#components` if you want or need
|
|
|
297
306
|
|
|
298
307
|
```vue [app/pages/index.vue]
|
|
299
308
|
<script setup lang="ts">
|
|
300
|
-
import {
|
|
309
|
+
import { LazyMountainsList, NuxtLink } from '#components'
|
|
301
310
|
|
|
302
311
|
const show = ref(false)
|
|
303
312
|
</script>
|
|
@@ -306,7 +315,12 @@ const show = ref(false)
|
|
|
306
315
|
<div>
|
|
307
316
|
<h1>Mountains</h1>
|
|
308
317
|
<LazyMountainsList v-if="show" />
|
|
309
|
-
<button
|
|
318
|
+
<button
|
|
319
|
+
v-if="!show"
|
|
320
|
+
@click="show = true"
|
|
321
|
+
>
|
|
322
|
+
Show List
|
|
323
|
+
</button>
|
|
310
324
|
<NuxtLink to="/">Home</NuxtLink>
|
|
311
325
|
</div>
|
|
312
326
|
</template>
|
|
@@ -333,8 +347,8 @@ export default defineNuxtConfig({
|
|
|
333
347
|
//
|
|
334
348
|
// ~/components/Btn.vue => <Btn />
|
|
335
349
|
// ~/components/base/Btn.vue => <BaseBtn />
|
|
336
|
-
'~/components'
|
|
337
|
-
]
|
|
350
|
+
'~/components',
|
|
351
|
+
],
|
|
338
352
|
})
|
|
339
353
|
```
|
|
340
354
|
|
|
@@ -352,7 +366,7 @@ If you want to auto-import components from an npm package, you can use [`addComp
|
|
|
352
366
|
import { addComponent, defineNuxtModule } from '@nuxt/kit'
|
|
353
367
|
|
|
354
368
|
export default defineNuxtModule({
|
|
355
|
-
setup() {
|
|
369
|
+
setup () {
|
|
356
370
|
// import { MyComponent as MyAutoImportedComponent } from 'my-npm-package'
|
|
357
371
|
addComponent({
|
|
358
372
|
name: 'MyAutoImportedComponent',
|
|
@@ -385,8 +399,8 @@ export default defineNuxtConfig({
|
|
|
385
399
|
{
|
|
386
400
|
path: '~/components',
|
|
387
401
|
extensions: ['.vue'], // [!code ++]
|
|
388
|
-
}
|
|
389
|
-
]
|
|
402
|
+
},
|
|
403
|
+
],
|
|
390
404
|
})
|
|
391
405
|
```
|
|
392
406
|
|
|
@@ -416,7 +430,7 @@ This feature only works with Nuxt auto-imports and `#components` imports. Explic
|
|
|
416
430
|
`.client` components are rendered only after being mounted. To access the rendered template using `onMounted()`, add `await nextTick()` in the callback of the `onMounted()` hook.
|
|
417
431
|
::
|
|
418
432
|
|
|
419
|
-
::read-more{to="/docs/api/components/client-only"}
|
|
433
|
+
::read-more{to="/docs/4.x/api/components/client-only"}
|
|
420
434
|
You can also achieve a similar result with the `<ClientOnly>` component.
|
|
421
435
|
::
|
|
422
436
|
|
|
@@ -424,7 +438,7 @@ You can also achieve a similar result with the `<ClientOnly>` component.
|
|
|
424
438
|
|
|
425
439
|
Server components allow server-rendering individual components within your client-side apps. It's possible to use server components within Nuxt, even if you are generating a static site. That makes it possible to build complex sites that mix dynamic components, server-rendered HTML and even static chunks of markup.
|
|
426
440
|
|
|
427
|
-
Server components can either be used on their own or paired with a [client component](/docs/guide/directory-structure/app/components#paired-with-a-client-component).
|
|
441
|
+
Server components can either be used on their own or paired with a [client component](/docs/4.x/guide/directory-structure/app/components#paired-with-a-client-component).
|
|
428
442
|
|
|
429
443
|
:video-accordion{title="Watch Learn Vue video about Nuxt Server Components" videoId="u1yyXe86xJM"}
|
|
430
444
|
|
|
@@ -443,8 +457,8 @@ Server components are currently experimental and in order to use them, you need
|
|
|
443
457
|
```ts twoslash [nuxt.config.ts]
|
|
444
458
|
export default defineNuxtConfig({
|
|
445
459
|
experimental: {
|
|
446
|
-
componentIslands: true
|
|
447
|
-
}
|
|
460
|
+
componentIslands: true,
|
|
461
|
+
},
|
|
448
462
|
})
|
|
449
463
|
```
|
|
450
464
|
|
|
@@ -498,7 +512,10 @@ You can partially hydrate a component by setting a `nuxt-client` attribute on th
|
|
|
498
512
|
<div>
|
|
499
513
|
<HighlightedMarkdown markdown="# Headline" />
|
|
500
514
|
<!-- Counter will be loaded and hydrated client-side -->
|
|
501
|
-
<Counter
|
|
515
|
+
<Counter
|
|
516
|
+
nuxt-client
|
|
517
|
+
:count="5"
|
|
518
|
+
/>
|
|
502
519
|
</div>
|
|
503
520
|
</template>
|
|
504
521
|
```
|
|
@@ -547,7 +564,7 @@ In this case, the `.server` + `.client` components are two 'halves' of a compone
|
|
|
547
564
|
|
|
548
565
|
There are a number of components that Nuxt provides, including `<ClientOnly>` and `<DevOnly>`. You can read more about them in the API documentation.
|
|
549
566
|
|
|
550
|
-
::read-more{to="/docs/api"}
|
|
567
|
+
::read-more{to="/docs/4.x/api"}
|
|
551
568
|
::
|
|
552
569
|
|
|
553
570
|
## Library Authors
|
|
@@ -573,10 +590,10 @@ Imagine a directory structure like this:
|
|
|
573
590
|
Then in `awesome-ui/nuxt.ts` you can use the `addComponentsDir` hook:
|
|
574
591
|
|
|
575
592
|
```ts twoslash
|
|
576
|
-
import { createResolver, defineNuxtModule
|
|
593
|
+
import { addComponentsDir, createResolver, defineNuxtModule } from '@nuxt/kit'
|
|
577
594
|
|
|
578
595
|
export default defineNuxtModule({
|
|
579
|
-
setup() {
|
|
596
|
+
setup () {
|
|
580
597
|
const resolver = createResolver(import.meta.url)
|
|
581
598
|
|
|
582
599
|
// Add ./components dir to the list
|
|
@@ -592,7 +609,7 @@ That's it! Now in your project, you can import your UI library as a Nuxt module
|
|
|
592
609
|
|
|
593
610
|
```ts twoslash [nuxt.config.ts]
|
|
594
611
|
export default defineNuxtConfig({
|
|
595
|
-
modules: ['awesome-ui/nuxt']
|
|
612
|
+
modules: ['awesome-ui/nuxt'],
|
|
596
613
|
})
|
|
597
614
|
```
|
|
598
615
|
|
|
@@ -609,4 +626,4 @@ export default defineNuxtConfig({
|
|
|
609
626
|
|
|
610
627
|
It will automatically import the components only if used and also support HMR when updating your components in `node_modules/awesome-ui/components/`.
|
|
611
628
|
|
|
612
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
629
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
@@ -9,7 +9,7 @@ navigation.icon: i-vscode-icons-folder-type-src
|
|
|
9
9
|
|
|
10
10
|
**Method 1:** Using named export
|
|
11
11
|
|
|
12
|
-
```
|
|
12
|
+
```ts [app/composables/useFoo.ts]
|
|
13
13
|
export const useFoo = () => {
|
|
14
14
|
return useState('foo', () => 'bar')
|
|
15
15
|
}
|
|
@@ -17,7 +17,7 @@ export const useFoo = () => {
|
|
|
17
17
|
|
|
18
18
|
**Method 2:** Using default export
|
|
19
19
|
|
|
20
|
-
```
|
|
20
|
+
```ts [app/composables/use-foo.ts or composables/useFoo.ts]
|
|
21
21
|
// It will be available as useFoo() (camelCase of file name without extension)
|
|
22
22
|
export default function () {
|
|
23
23
|
return useState('foo', () => 'bar')
|
|
@@ -42,9 +42,9 @@ const foo = useFoo()
|
|
|
42
42
|
The `app/composables/` directory in Nuxt does not provide any additional reactivity capabilities to your code. Instead, any reactivity within composables is achieved using Vue's Composition API mechanisms, such as ref and reactive. Note that reactive code is also not limited to the boundaries of the `app/composables/` directory. You are free to employ reactivity features wherever they're needed in your application.
|
|
43
43
|
::
|
|
44
44
|
|
|
45
|
-
:read-more{to="/docs/guide/concepts/auto-imports"}
|
|
45
|
+
:read-more{to="/docs/4.x/guide/concepts/auto-imports"}
|
|
46
46
|
|
|
47
|
-
:link-example{to="/docs/examples/features/auto-imports"}
|
|
47
|
+
:link-example{to="/docs/4.x/examples/features/auto-imports"}
|
|
48
48
|
|
|
49
49
|
## Types
|
|
50
50
|
|
|
@@ -62,7 +62,7 @@ If you create a composable without having the dev server running, TypeScript wil
|
|
|
62
62
|
|
|
63
63
|
You can use a composable within another composable using auto imports:
|
|
64
64
|
|
|
65
|
-
```
|
|
65
|
+
```ts [app/composables/test.ts]
|
|
66
66
|
export const useFoo = () => {
|
|
67
67
|
const nuxtApp = useNuxtApp()
|
|
68
68
|
const bar = useBar()
|
|
@@ -73,7 +73,7 @@ export const useFoo = () => {
|
|
|
73
73
|
|
|
74
74
|
You can access [plugin injections](/docs/4.x/guide/directory-structure/plugins#providing-helpers) from composables:
|
|
75
75
|
|
|
76
|
-
```
|
|
76
|
+
```ts [app/composables/test.ts]
|
|
77
77
|
export const useHello = () => {
|
|
78
78
|
const nuxtApp = useNuxtApp()
|
|
79
79
|
return nuxtApp.$hello
|
|
@@ -114,8 +114,8 @@ export default defineNuxtConfig({
|
|
|
114
114
|
// ... or scan composables nested one level deep with a specific name and file extension
|
|
115
115
|
'~/composables/*/index.{ts,js,mjs,mts}',
|
|
116
116
|
// ... or scan all composables within given directory
|
|
117
|
-
'~/composables/**'
|
|
118
|
-
]
|
|
119
|
-
}
|
|
117
|
+
'~/composables/**',
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
120
|
})
|
|
121
121
|
```
|
|
@@ -69,12 +69,12 @@ Then you can use the `custom` layout in your page:
|
|
|
69
69
|
```vue twoslash [pages/about.vue]
|
|
70
70
|
<script setup lang="ts">
|
|
71
71
|
definePageMeta({
|
|
72
|
-
layout: 'custom'
|
|
72
|
+
layout: 'custom',
|
|
73
73
|
})
|
|
74
74
|
</script>
|
|
75
75
|
```
|
|
76
76
|
|
|
77
|
-
::read-more{to="/docs/guide/directory-structure/app/pages#page-metadata"}
|
|
77
|
+
::read-more{to="/docs/4.x/guide/directory-structure/app/pages#page-metadata"}
|
|
78
78
|
Learn more about `definePageMeta`.
|
|
79
79
|
::
|
|
80
80
|
|
|
@@ -83,7 +83,7 @@ You can directly override the default layout for all pages using the `name` prop
|
|
|
83
83
|
```vue [app/app.vue]
|
|
84
84
|
<script setup lang="ts">
|
|
85
85
|
// You might choose this based on an API call or logged-in status
|
|
86
|
-
const layout =
|
|
86
|
+
const layout = 'custom'
|
|
87
87
|
</script>
|
|
88
88
|
|
|
89
89
|
<template>
|
|
@@ -109,7 +109,7 @@ File | Layout Name
|
|
|
109
109
|
`~/layouts/desktop-base/DesktopBase.vue` | `desktop-base`
|
|
110
110
|
`~/layouts/desktop/Desktop.vue` | `desktop`
|
|
111
111
|
|
|
112
|
-
:link-example{to="/docs/examples/features/layouts"}
|
|
112
|
+
:link-example{to="/docs/4.x/examples/features/layouts"}
|
|
113
113
|
|
|
114
114
|
## Changing the Layout Dynamically
|
|
115
115
|
|
|
@@ -122,17 +122,19 @@ function enableCustomLayout () {
|
|
|
122
122
|
}
|
|
123
123
|
definePageMeta({
|
|
124
124
|
layout: false,
|
|
125
|
-
})
|
|
125
|
+
})
|
|
126
126
|
</script>
|
|
127
127
|
|
|
128
128
|
<template>
|
|
129
129
|
<div>
|
|
130
|
-
<button @click="enableCustomLayout">
|
|
130
|
+
<button @click="enableCustomLayout">
|
|
131
|
+
Update layout
|
|
132
|
+
</button>
|
|
131
133
|
</div>
|
|
132
134
|
</template>
|
|
133
135
|
```
|
|
134
136
|
|
|
135
|
-
:link-example{to="/docs/examples/features/layouts"}
|
|
137
|
+
:link-example{to="/docs/4.x/examples/features/layouts"}
|
|
136
138
|
|
|
137
139
|
## Overriding a Layout on a Per-page Basis
|
|
138
140
|
|
|
@@ -150,7 +152,9 @@ definePageMeta({
|
|
|
150
152
|
<template>
|
|
151
153
|
<div>
|
|
152
154
|
<NuxtLayout name="custom">
|
|
153
|
-
<template #header>
|
|
155
|
+
<template #header>
|
|
156
|
+
Some header template content.
|
|
157
|
+
</template>
|
|
154
158
|
|
|
155
159
|
The rest of the page
|
|
156
160
|
</NuxtLayout>
|