@nuxt/docs 0.0.0 → 3.17.1
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/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: '<NuxtRouteAnnouncer>'
|
|
3
|
+
description: 'The <NuxtRouteAnnouncer> component adds a hidden element with the page title to announce route changes to assistive technologies.'
|
|
4
|
+
navigation:
|
|
5
|
+
badge: New
|
|
6
|
+
links:
|
|
7
|
+
- label: Source
|
|
8
|
+
icon: i-simple-icons-github
|
|
9
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-route-announcer.ts
|
|
10
|
+
size: xs
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
This component is available in Nuxt v3.12+.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
Add `<NuxtRouteAnnouncer/>` in your [`app.vue`](/docs/guide/directory-structure/app) or [`layouts/`](/docs/guide/directory-structure/layouts) to enhance accessibility by informing assistive technologies about page title changes. This ensures that navigational changes are announced to users relying on screen readers.
|
|
20
|
+
|
|
21
|
+
```vue [app.vue]
|
|
22
|
+
<template>
|
|
23
|
+
<NuxtRouteAnnouncer />
|
|
24
|
+
<NuxtLayout>
|
|
25
|
+
<NuxtPage />
|
|
26
|
+
</NuxtLayout>
|
|
27
|
+
</template>
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Slots
|
|
31
|
+
|
|
32
|
+
You can pass custom HTML or components through the route announcer's default slot.
|
|
33
|
+
|
|
34
|
+
```vue
|
|
35
|
+
<template>
|
|
36
|
+
<NuxtRouteAnnouncer>
|
|
37
|
+
<template #default="{ message }">
|
|
38
|
+
<p>{{ message }} was loaded.</p>
|
|
39
|
+
</template>
|
|
40
|
+
</NuxtRouteAnnouncer>
|
|
41
|
+
</template>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Props
|
|
45
|
+
|
|
46
|
+
- `atomic`: Controls if screen readers only announce changes or the entire content. Set to true for full content readouts on updates, false for changes only. (default `false`)
|
|
47
|
+
- `politeness`: Sets the urgency for screen reader announcements: `off` (disable the announcement), `polite` (waits for silence), or `assertive` (interrupts immediately). (default `polite`)
|
|
48
|
+
|
|
49
|
+
::callout
|
|
50
|
+
This component is optional. :br
|
|
51
|
+
To achieve full customization, you can implement your own one based on [its source code](https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-route-announcer.ts).
|
|
52
|
+
::
|
|
53
|
+
|
|
54
|
+
::callout
|
|
55
|
+
You can hook into the underlying announcer instance using [the `useRouteAnnouncer` composable](/docs/api/composables/use-route-announcer), which allows you to set a custom announcement message.
|
|
56
|
+
::
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: '<NuxtTime>'
|
|
3
|
+
description: 'The <NuxtTime> component displays time in a locale-friendly format with server-client consistency.'
|
|
4
|
+
navigation:
|
|
5
|
+
badge: New
|
|
6
|
+
links:
|
|
7
|
+
- label: Source
|
|
8
|
+
icon: i-simple-icons-github
|
|
9
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-time.vue
|
|
10
|
+
size: xs
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
This component is available in Nuxt v3.17+.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
The `<NuxtTime>` component lets you display dates and times in a locale-friendly format with proper `<time>` HTML semantics. It ensures consistent rendering between server and client without hydration mismatches.
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
You can use the `<NuxtTime>` component anywhere in your app:
|
|
22
|
+
|
|
23
|
+
```vue
|
|
24
|
+
<template>
|
|
25
|
+
<NuxtTime :datetime="Date.now()" />
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Props
|
|
30
|
+
|
|
31
|
+
### `datetime`
|
|
32
|
+
|
|
33
|
+
- Type: `Date | number | string`
|
|
34
|
+
- Required: `true`
|
|
35
|
+
|
|
36
|
+
The date and time value to display. You can provide:
|
|
37
|
+
- A `Date` object
|
|
38
|
+
- A timestamp (number)
|
|
39
|
+
- An ISO-formatted date string
|
|
40
|
+
|
|
41
|
+
```vue
|
|
42
|
+
<template>
|
|
43
|
+
<NuxtTime :datetime="Date.now()" />
|
|
44
|
+
<NuxtTime :datetime="new Date()" />
|
|
45
|
+
<NuxtTime datetime="2023-06-15T09:30:00.000Z" />
|
|
46
|
+
</template>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### `locale`
|
|
50
|
+
|
|
51
|
+
- Type: `string`
|
|
52
|
+
- Required: `false`
|
|
53
|
+
- Default: Uses the browser or server's default locale
|
|
54
|
+
|
|
55
|
+
The [BCP 47 language tag](https://datatracker.ietf.org/doc/html/rfc5646) for formatting (e.g., 'en-US', 'fr-FR', 'ja-JP'):
|
|
56
|
+
|
|
57
|
+
```vue
|
|
58
|
+
<template>
|
|
59
|
+
<NuxtTime :datetime="Date.now()" locale="fr-FR" />
|
|
60
|
+
</template>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Formatting Props
|
|
64
|
+
|
|
65
|
+
The component accepts any property from the [Intl.DateTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) options:
|
|
66
|
+
|
|
67
|
+
```vue
|
|
68
|
+
<template>
|
|
69
|
+
<NuxtTime
|
|
70
|
+
:datetime="Date.now()"
|
|
71
|
+
year="numeric"
|
|
72
|
+
month="long"
|
|
73
|
+
day="numeric"
|
|
74
|
+
hour="2-digit"
|
|
75
|
+
minute="2-digit"
|
|
76
|
+
/>
|
|
77
|
+
</template>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This would output something like: "April 22, 2025, 08:30 AM"
|
|
81
|
+
|
|
82
|
+
### `relative`
|
|
83
|
+
|
|
84
|
+
- Type: `boolean`
|
|
85
|
+
- Required: `false`
|
|
86
|
+
- Default: `false`
|
|
87
|
+
|
|
88
|
+
Enables relative time formatting using the Intl.RelativeTimeFormat API:
|
|
89
|
+
|
|
90
|
+
```vue
|
|
91
|
+
<template>
|
|
92
|
+
<!-- Shows something like "5 minutes ago" -->
|
|
93
|
+
<NuxtTime :datetime="Date.now() - 5 * 60 * 1000" relative />
|
|
94
|
+
</template>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Relative Time Formatting Props
|
|
98
|
+
|
|
99
|
+
When `relative` is set to `true`, the component also accepts properties from [Intl.RelativeTimeFormat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat/RelativeTimeFormat):
|
|
100
|
+
|
|
101
|
+
```vue
|
|
102
|
+
<template>
|
|
103
|
+
<NuxtTime
|
|
104
|
+
:datetime="Date.now() - 3 * 24 * 60 * 60 * 1000"
|
|
105
|
+
relative
|
|
106
|
+
numeric="auto"
|
|
107
|
+
style="long"
|
|
108
|
+
/>
|
|
109
|
+
</template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
This would output something like: "3 days ago" or "last Friday" depending on the `numeric` setting.
|
|
113
|
+
|
|
114
|
+
## Examples
|
|
115
|
+
|
|
116
|
+
### Basic Usage
|
|
117
|
+
|
|
118
|
+
```vue
|
|
119
|
+
<template>
|
|
120
|
+
<NuxtTime :datetime="Date.now()" />
|
|
121
|
+
</template>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Custom Formatting
|
|
125
|
+
|
|
126
|
+
```vue
|
|
127
|
+
<template>
|
|
128
|
+
<NuxtTime
|
|
129
|
+
:datetime="Date.now()"
|
|
130
|
+
weekday="long"
|
|
131
|
+
year="numeric"
|
|
132
|
+
month="short"
|
|
133
|
+
day="numeric"
|
|
134
|
+
hour="numeric"
|
|
135
|
+
minute="numeric"
|
|
136
|
+
second="numeric"
|
|
137
|
+
timeZoneName="short"
|
|
138
|
+
/>
|
|
139
|
+
</template>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Relative Time
|
|
143
|
+
|
|
144
|
+
```vue
|
|
145
|
+
<template>
|
|
146
|
+
<div>
|
|
147
|
+
<p>
|
|
148
|
+
<NuxtTime :datetime="Date.now() - 30 * 1000" relative />
|
|
149
|
+
<!-- 30 seconds ago -->
|
|
150
|
+
</p>
|
|
151
|
+
<p>
|
|
152
|
+
<NuxtTime :datetime="Date.now() - 45 * 60 * 1000" relative />
|
|
153
|
+
<!-- 45 minutes ago -->
|
|
154
|
+
</p>
|
|
155
|
+
<p>
|
|
156
|
+
<NuxtTime :datetime="Date.now() + 2 * 24 * 60 * 60 * 1000" relative />
|
|
157
|
+
<!-- in 2 days -->
|
|
158
|
+
</p>
|
|
159
|
+
</div>
|
|
160
|
+
</template>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### With Custom Locale
|
|
164
|
+
|
|
165
|
+
```vue
|
|
166
|
+
<template>
|
|
167
|
+
<div>
|
|
168
|
+
<NuxtTime :datetime="Date.now()" locale="en-US" weekday="long" />
|
|
169
|
+
<NuxtTime :datetime="Date.now()" locale="fr-FR" weekday="long" />
|
|
170
|
+
<NuxtTime :datetime="Date.now()" locale="ja-JP" weekday="long" />
|
|
171
|
+
</div>
|
|
172
|
+
</template>
|
|
173
|
+
```
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtPage>"
|
|
3
|
+
description: The <NuxtPage> component is required to display pages located in the pages/ directory.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/pages/runtime/page.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`<NuxtPage>` is a built-in component that comes with Nuxt. It lets you display top-level or nested pages located in the [`pages/`](/docs/guide/directory-structure/pages) directory.
|
|
12
|
+
|
|
13
|
+
::note
|
|
14
|
+
`<NuxtPage>` is a wrapper around [`<RouterView>`](https://router.vuejs.org/api/interfaces/RouterViewProps.html#interface-routerviewprops) from Vue Router. It should be used instead of `<RouterView>` because the former takes additional care of internal states. Otherwise, `useRoute()` may return incorrect paths.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
`<NuxtPage>` includes the following components:
|
|
18
|
+
|
|
19
|
+
```vue
|
|
20
|
+
<template>
|
|
21
|
+
<RouterView #default="{ Component }">
|
|
22
|
+
<!-- Optional, when using transitions -->
|
|
23
|
+
<Transition>
|
|
24
|
+
<!-- Optional, when using keep-alive -->
|
|
25
|
+
<KeepAlive>
|
|
26
|
+
<Suspense>
|
|
27
|
+
<component :is="Component" />
|
|
28
|
+
</Suspense>
|
|
29
|
+
</KeepAlive>
|
|
30
|
+
</Transition>
|
|
31
|
+
</RouterView>
|
|
32
|
+
</template>
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
By default, Nuxt does not enable `<Transition>` and `<KeepAlive>`. You can enable them in the nuxt.config file or by setting the `transition` and `keepalive` properties on `<NuxtPage>`. If you want to define a specific page, you can set it in `definePageMeta` in the page component.
|
|
36
|
+
|
|
37
|
+
::warning
|
|
38
|
+
If you enable `<Transition>` in your page component, ensure that the page has a single root element.
|
|
39
|
+
::
|
|
40
|
+
|
|
41
|
+
Since `<NuxtPage>` uses `<Suspense>` under the hood, the component lifecycle behavior during page changes differs from that of a typical Vue application.
|
|
42
|
+
|
|
43
|
+
In a typical Vue application, a new page component is mounted **only after** the previous one has been fully unmounted. However, in Nuxt, due to how Vue `<Suspense>` is implemented, the new page component is mounted **before** the previous one is unmounted.
|
|
44
|
+
|
|
45
|
+
## Props
|
|
46
|
+
|
|
47
|
+
- `name`: tells `<RouterView>` to render the component with the corresponding name in the matched route record's components option.
|
|
48
|
+
- type: `string`
|
|
49
|
+
- `route`: route location that has all of its components resolved.
|
|
50
|
+
- type: `RouteLocationNormalized`
|
|
51
|
+
- `pageKey`: control when the `NuxtPage` component is re-rendered.
|
|
52
|
+
- type: `string` or `function`
|
|
53
|
+
- `transition`: define global transitions for all pages rendered with the `NuxtPage` component.
|
|
54
|
+
- type: `boolean` or [`TransitionProps`](https://vuejs.org/api/built-in-components#transition)
|
|
55
|
+
- `keepalive`: control state preservation of pages rendered with the `NuxtPage` component.
|
|
56
|
+
- type: `boolean` or [`KeepAliveProps`](https://vuejs.org/api/built-in-components#keepalive)
|
|
57
|
+
|
|
58
|
+
::tip
|
|
59
|
+
Nuxt automatically resolves the `name` and `route` by scanning and rendering all Vue component files found in the `/pages` directory.
|
|
60
|
+
::
|
|
61
|
+
|
|
62
|
+
## Example
|
|
63
|
+
|
|
64
|
+
For example, if you pass a key that never changes, the `<NuxtPage>` component will be rendered only once - when it is first mounted.
|
|
65
|
+
|
|
66
|
+
```vue [app.vue]
|
|
67
|
+
<template>
|
|
68
|
+
<NuxtPage page-key="static" />
|
|
69
|
+
</template>
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
You can also use a dynamic key based on the current route:
|
|
73
|
+
|
|
74
|
+
```html
|
|
75
|
+
<NuxtPage :page-key="route => route.fullPath" />
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
::warning
|
|
79
|
+
Don't use `$route` object here as it can cause problems with how `<NuxtPage>` renders pages with `<Suspense>`.
|
|
80
|
+
::
|
|
81
|
+
|
|
82
|
+
Alternatively, `pageKey` can be passed as a `key` value via [`definePageMeta`](/docs/api/utils/define-page-meta) from the `<script>` section of your Vue component in the `/pages` directory.
|
|
83
|
+
|
|
84
|
+
```vue [pages/my-page.vue]
|
|
85
|
+
<script setup lang="ts">
|
|
86
|
+
definePageMeta({
|
|
87
|
+
key: route => route.fullPath
|
|
88
|
+
})
|
|
89
|
+
</script>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
:link-example{to="/docs/examples/routing/pages"}
|
|
93
|
+
|
|
94
|
+
## Page's Ref
|
|
95
|
+
|
|
96
|
+
To get the `ref` of a page component, access it through `ref.value.pageRef`
|
|
97
|
+
|
|
98
|
+
````vue [app.vue]
|
|
99
|
+
<script setup lang="ts">
|
|
100
|
+
const page = ref()
|
|
101
|
+
|
|
102
|
+
function logFoo () {
|
|
103
|
+
page.value.pageRef.foo()
|
|
104
|
+
}
|
|
105
|
+
</script>
|
|
106
|
+
|
|
107
|
+
<template>
|
|
108
|
+
<NuxtPage ref="page" />
|
|
109
|
+
</template>
|
|
110
|
+
````
|
|
111
|
+
|
|
112
|
+
````vue [my-page.vue]
|
|
113
|
+
<script setup lang="ts">
|
|
114
|
+
const foo = () => {
|
|
115
|
+
console.log('foo method called')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
defineExpose({
|
|
119
|
+
foo,
|
|
120
|
+
})
|
|
121
|
+
</script>
|
|
122
|
+
````
|
|
123
|
+
|
|
124
|
+
## Custom Props
|
|
125
|
+
|
|
126
|
+
`<NuxtPage>` also accepts custom props that you may need to pass further down the hierarchy.
|
|
127
|
+
|
|
128
|
+
For example, in the below example, the value of `foobar` will be passed to the `NuxtPage` component and then to the page components.
|
|
129
|
+
|
|
130
|
+
```vue [app.vue]
|
|
131
|
+
<template>
|
|
132
|
+
<NuxtPage :foobar="123" />
|
|
133
|
+
</template>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
We can access the `foobar` prop in the page component:
|
|
137
|
+
|
|
138
|
+
```vue [pages/page.vue]
|
|
139
|
+
<script setup lang="ts">
|
|
140
|
+
const props = defineProps<{ foobar: number }>()
|
|
141
|
+
|
|
142
|
+
console.log(props.foobar) // Outputs: 123
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
If you have not defined the prop with `defineProps`, any props passed down to `NuxtPage` can still be accessed directly from the page `attrs`:
|
|
146
|
+
|
|
147
|
+
```vue [pages/page.vue]
|
|
148
|
+
<script setup lang="ts">
|
|
149
|
+
const attrs = useAttrs()
|
|
150
|
+
console.log(attrs.foobar) // Outputs: 123
|
|
151
|
+
</script>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
:read-more{to="/docs/guide/directory-structure/pages"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "<NuxtLayout>"
|
|
3
|
+
description: "Nuxt provides the <NuxtLayout> component to show layouts on pages and error pages."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/components/nuxt-layout.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
You can use `<NuxtLayout />` component to activate the `default` layout on `app.vue` or `error.vue`.
|
|
12
|
+
|
|
13
|
+
```vue [app.vue]
|
|
14
|
+
<template>
|
|
15
|
+
<NuxtLayout>
|
|
16
|
+
some page content
|
|
17
|
+
</NuxtLayout>
|
|
18
|
+
</template>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
:read-more{to="/docs/guide/directory-structure/layouts"}
|
|
22
|
+
|
|
23
|
+
## Props
|
|
24
|
+
|
|
25
|
+
- `name`: Specify a layout name to be rendered, can be a string, reactive reference or a computed property. It **must** match the name of the corresponding layout file in the [`layouts/`](/docs/guide/directory-structure/layouts) directory.
|
|
26
|
+
- **type**: `string`
|
|
27
|
+
- **default**: `default`
|
|
28
|
+
|
|
29
|
+
```vue [pages/index.vue]
|
|
30
|
+
<script setup lang="ts">
|
|
31
|
+
// layouts/custom.vue
|
|
32
|
+
const layout = 'custom'
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<template>
|
|
36
|
+
<NuxtLayout :name="layout">
|
|
37
|
+
<NuxtPage />
|
|
38
|
+
</NuxtLayout>
|
|
39
|
+
</template>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
::note
|
|
43
|
+
Please note the layout name is normalized to kebab-case, so if your layout file is named `errorLayout.vue`, it will become `error-layout` when passed as a `name` property to `<NuxtLayout />`.
|
|
44
|
+
::
|
|
45
|
+
|
|
46
|
+
```vue [error.vue]
|
|
47
|
+
<template>
|
|
48
|
+
<NuxtLayout name="error-layout">
|
|
49
|
+
<NuxtPage />
|
|
50
|
+
</NuxtLayout>
|
|
51
|
+
</template>
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
::read-more{to="/docs/guide/directory-structure/layouts"}
|
|
55
|
+
Read more about dynamic layouts.
|
|
56
|
+
::
|
|
57
|
+
|
|
58
|
+
- `fallback`: If an invalid layout is passed to the `name` prop, no layout will be rendered. Specify a `fallback` layout to be rendered in this scenario. It **must** match the name of the corresponding layout file in the [`layouts/`](/docs/guide/directory-structure/layouts) directory.
|
|
59
|
+
- **type**: `string`
|
|
60
|
+
- **default**: `null`
|
|
61
|
+
|
|
62
|
+
## Additional Props
|
|
63
|
+
|
|
64
|
+
`NuxtLayout` also accepts any additional props that you may need to pass to the layout. These custom props are then made accessible as attributes.
|
|
65
|
+
|
|
66
|
+
```vue [pages/some-page.vue]
|
|
67
|
+
<template>
|
|
68
|
+
<div>
|
|
69
|
+
<NuxtLayout name="custom" title="I am a custom layout">
|
|
70
|
+
<-- ... -->
|
|
71
|
+
</NuxtLayout>
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In the above example, the value of `title` will be available using `$attrs.title` in the template or `useAttrs().title` in `<script setup>` at custom.vue.
|
|
77
|
+
|
|
78
|
+
```vue [layouts/custom.vue]
|
|
79
|
+
<script setup lang="ts">
|
|
80
|
+
const layoutCustomProps = useAttrs()
|
|
81
|
+
|
|
82
|
+
console.log(layoutCustomProps.title) // I am a custom layout
|
|
83
|
+
</script>
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Transitions
|
|
87
|
+
|
|
88
|
+
`<NuxtLayout />` renders incoming content via `<slot />`, which is then wrapped around Vue’s `<Transition />` component to activate layout transition. For this to work as expected, it is recommended that `<NuxtLayout />` is **not** the root element of the page component.
|
|
89
|
+
|
|
90
|
+
::code-group
|
|
91
|
+
|
|
92
|
+
```vue [pages/index.vue]
|
|
93
|
+
<template>
|
|
94
|
+
<div>
|
|
95
|
+
<NuxtLayout name="custom">
|
|
96
|
+
<template #header> Some header template content. </template>
|
|
97
|
+
</NuxtLayout>
|
|
98
|
+
</div>
|
|
99
|
+
</template>
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
```vue [layouts/custom.vue]
|
|
103
|
+
<template>
|
|
104
|
+
<div>
|
|
105
|
+
<!-- named slot -->
|
|
106
|
+
<slot name="header" />
|
|
107
|
+
<slot />
|
|
108
|
+
</div>
|
|
109
|
+
</template>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
::
|
|
113
|
+
|
|
114
|
+
:read-more{to="/docs/getting-started/transitions"}
|
|
115
|
+
|
|
116
|
+
## Layout's Ref
|
|
117
|
+
|
|
118
|
+
To get the ref of a layout component, access it through `ref.value.layoutRef`.
|
|
119
|
+
|
|
120
|
+
::code-group
|
|
121
|
+
|
|
122
|
+
```vue [app.vue]
|
|
123
|
+
<script setup lang="ts">
|
|
124
|
+
const layout = ref()
|
|
125
|
+
|
|
126
|
+
function logFoo () {
|
|
127
|
+
layout.value.layoutRef.foo()
|
|
128
|
+
}
|
|
129
|
+
</script>
|
|
130
|
+
|
|
131
|
+
<template>
|
|
132
|
+
<NuxtLayout ref="layout">
|
|
133
|
+
default layout
|
|
134
|
+
</NuxtLayout>
|
|
135
|
+
</template>
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
```vue [layouts/default.vue]
|
|
139
|
+
<script setup lang="ts">
|
|
140
|
+
const foo = () => console.log('foo')
|
|
141
|
+
defineExpose({
|
|
142
|
+
foo
|
|
143
|
+
})
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<template>
|
|
147
|
+
<div>
|
|
148
|
+
default layout
|
|
149
|
+
<slot />
|
|
150
|
+
</div>
|
|
151
|
+
</template>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
::
|
|
155
|
+
|
|
156
|
+
:read-more{to="/docs/guide/directory-structure/layouts"}
|