@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 4.1.3-29316225.304409da
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/03.configuration.md +19 -19
- package/1.getting-started/04.views.md +1 -1
- package/1.getting-started/05.assets.md +8 -2
- package/1.getting-started/06.styling.md +50 -40
- package/1.getting-started/07.routing.md +4 -4
- package/1.getting-started/08.seo-meta.md +46 -33
- package/1.getting-started/09.transitions.md +38 -33
- package/1.getting-started/10.data-fetching.md +47 -39
- package/1.getting-started/11.state-management.md +15 -8
- package/1.getting-started/12.error-handling.md +6 -4
- package/1.getting-started/13.server.md +3 -3
- package/1.getting-started/14.layers.md +18 -12
- package/1.getting-started/15.prerendering.md +24 -24
- package/1.getting-started/16.deployment.md +7 -7
- package/1.getting-started/17.testing.md +41 -41
- package/1.getting-started/18.upgrade.md +48 -66
- package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
- package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
- package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
- package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
- package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
- package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
- package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
- package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
- 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 +4 -4
- package/2.guide/1.directory-structure/1.public.md +1 -1
- package/2.guide/1.directory-structure/1.server.md +28 -28
- package/2.guide/1.directory-structure/1.shared.md +1 -1
- package/2.guide/2.concepts/1.auto-imports.md +11 -11
- package/2.guide/2.concepts/2.vuejs-development.md +5 -5
- package/2.guide/2.concepts/3.rendering.md +14 -12
- package/2.guide/2.concepts/5.modules.md +2 -2
- package/2.guide/2.concepts/7.esm.md +14 -12
- package/2.guide/2.concepts/8.typescript.md +4 -4
- package/2.guide/3.going-further/1.events.md +2 -2
- package/2.guide/3.going-further/1.experimental-features.md +234 -73
- 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 +7 -7
- package/2.guide/3.going-further/2.hooks.md +8 -8
- package/2.guide/3.going-further/3.modules.md +76 -74
- package/2.guide/3.going-further/4.kit.md +3 -3
- package/2.guide/3.going-further/6.nuxt-app.md +1 -1
- package/2.guide/3.going-further/7.layers.md +50 -41
- 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 +9 -9
- package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
- package/2.guide/5.best-practices/performance.md +8 -8
- 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/11.teleports.md +4 -1
- 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 +2 -2
- package/3.api/1.components/3.nuxt-layout.md +9 -4
- package/3.api/1.components/4.nuxt-link.md +38 -18
- 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 +11 -11
- package/3.api/2.composables/use-cookie.md +26 -18
- package/3.api/2.composables/use-error.md +1 -1
- package/3.api/2.composables/use-fetch.md +13 -13
- package/3.api/2.composables/use-head-safe.md +5 -5
- package/3.api/2.composables/use-head.md +2 -2
- package/3.api/2.composables/use-hydration.md +5 -5
- package/3.api/2.composables/use-loading-indicator.md +10 -10
- package/3.api/2.composables/use-nuxt-app.md +9 -9
- 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 +5 -3
- package/3.api/2.composables/use-runtime-config.md +6 -6
- package/3.api/2.composables/use-runtime-hook.md +1 -1
- package/3.api/2.composables/use-seo-meta.md +1 -1
- package/3.api/2.composables/use-server-seo-meta.md +1 -1
- package/3.api/2.composables/use-state.md +3 -3
- package/3.api/3.utils/$fetch.md +5 -3
- 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 +3 -3
- package/3.api/3.utils/clear-error.md +1 -1
- 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 +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 +11 -11
- package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
- package/3.api/3.utils/define-page-meta.md +14 -14
- package/3.api/3.utils/define-route-rules.md +3 -3
- package/3.api/3.utils/navigate-to.md +9 -9
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/prerender-routes.md +2 -2
- package/3.api/3.utils/refresh-cookie.md +3 -3
- package/3.api/3.utils/refresh-nuxt-data.md +9 -4
- package/3.api/3.utils/reload-nuxt-app.md +2 -2
- package/3.api/3.utils/set-response-status.md +1 -1
- package/3.api/3.utils/show-error.md +2 -2
- package/3.api/3.utils/update-app-config.md +2 -1
- package/3.api/4.commands/prepare.md +4 -0
- 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/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +293 -858
- 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 +2 -2
- package/6.bridge/4.plugins-and-middleware.md +5 -5
- package/6.bridge/5.nuxt3-compatible-api.md +11 -8
- 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/2.configuration.md +17 -15
- package/7.migration/4.meta.md +17 -14
- package/7.migration/5.plugins-and-middleware.md +5 -5
- package/7.migration/6.pages-and-layouts.md +15 -11
- package/7.migration/7.component-options.md +3 -3
- package/7.migration/8.runtime-config.md +3 -3
- package/package.json +1 -1
|
@@ -56,7 +56,10 @@ The [BCP 47 language tag](https://datatracker.ietf.org/doc/html/rfc5646) for for
|
|
|
56
56
|
|
|
57
57
|
```vue
|
|
58
58
|
<template>
|
|
59
|
-
<NuxtTime
|
|
59
|
+
<NuxtTime
|
|
60
|
+
:datetime="Date.now()"
|
|
61
|
+
locale="fr-FR"
|
|
62
|
+
/>
|
|
60
63
|
</template>
|
|
61
64
|
```
|
|
62
65
|
|
|
@@ -66,8 +69,8 @@ The component accepts any property from the [Intl.DateTimeFormat](https://develo
|
|
|
66
69
|
|
|
67
70
|
```vue
|
|
68
71
|
<template>
|
|
69
|
-
<NuxtTime
|
|
70
|
-
:datetime="Date.now()"
|
|
72
|
+
<NuxtTime
|
|
73
|
+
:datetime="Date.now()"
|
|
71
74
|
year="numeric"
|
|
72
75
|
month="long"
|
|
73
76
|
day="numeric"
|
|
@@ -90,7 +93,10 @@ Enables relative time formatting using the Intl.RelativeTimeFormat API:
|
|
|
90
93
|
```vue
|
|
91
94
|
<template>
|
|
92
95
|
<!-- Shows something like "5 minutes ago" -->
|
|
93
|
-
<NuxtTime
|
|
96
|
+
<NuxtTime
|
|
97
|
+
:datetime="Date.now() - 5 * 60 * 1000"
|
|
98
|
+
relative
|
|
99
|
+
/>
|
|
94
100
|
</template>
|
|
95
101
|
```
|
|
96
102
|
|
|
@@ -100,9 +106,9 @@ When `relative` is set to `true`, the component also accepts properties from [In
|
|
|
100
106
|
|
|
101
107
|
```vue
|
|
102
108
|
<template>
|
|
103
|
-
<NuxtTime
|
|
104
|
-
:datetime="Date.now() - 3 * 24 * 60 * 60 * 1000"
|
|
105
|
-
relative
|
|
109
|
+
<NuxtTime
|
|
110
|
+
:datetime="Date.now() - 3 * 24 * 60 * 60 * 1000"
|
|
111
|
+
relative
|
|
106
112
|
numeric="auto"
|
|
107
113
|
style="long"
|
|
108
114
|
/>
|
|
@@ -125,8 +131,8 @@ This would output something like: "3 days ago" or "last Friday" depending on the
|
|
|
125
131
|
|
|
126
132
|
```vue
|
|
127
133
|
<template>
|
|
128
|
-
<NuxtTime
|
|
129
|
-
:datetime="Date.now()"
|
|
134
|
+
<NuxtTime
|
|
135
|
+
:datetime="Date.now()"
|
|
130
136
|
weekday="long"
|
|
131
137
|
year="numeric"
|
|
132
138
|
month="short"
|
|
@@ -134,7 +140,7 @@ This would output something like: "3 days ago" or "last Friday" depending on the
|
|
|
134
140
|
hour="numeric"
|
|
135
141
|
minute="numeric"
|
|
136
142
|
second="numeric"
|
|
137
|
-
|
|
143
|
+
time-zone-name="short"
|
|
138
144
|
/>
|
|
139
145
|
</template>
|
|
140
146
|
```
|
|
@@ -145,15 +151,24 @@ This would output something like: "3 days ago" or "last Friday" depending on the
|
|
|
145
151
|
<template>
|
|
146
152
|
<div>
|
|
147
153
|
<p>
|
|
148
|
-
<NuxtTime
|
|
154
|
+
<NuxtTime
|
|
155
|
+
:datetime="Date.now() - 30 * 1000"
|
|
156
|
+
relative
|
|
157
|
+
/>
|
|
149
158
|
<!-- 30 seconds ago -->
|
|
150
159
|
</p>
|
|
151
|
-
<p>
|
|
152
|
-
<NuxtTime
|
|
160
|
+
<p>
|
|
161
|
+
<NuxtTime
|
|
162
|
+
:datetime="Date.now() - 45 * 60 * 1000"
|
|
163
|
+
relative
|
|
164
|
+
/>
|
|
153
165
|
<!-- 45 minutes ago -->
|
|
154
166
|
</p>
|
|
155
167
|
<p>
|
|
156
|
-
<NuxtTime
|
|
168
|
+
<NuxtTime
|
|
169
|
+
:datetime="Date.now() + 2 * 24 * 60 * 60 * 1000"
|
|
170
|
+
relative
|
|
171
|
+
/>
|
|
157
172
|
<!-- in 2 days -->
|
|
158
173
|
</p>
|
|
159
174
|
</div>
|
|
@@ -165,9 +180,21 @@ This would output something like: "3 days ago" or "last Friday" depending on the
|
|
|
165
180
|
```vue
|
|
166
181
|
<template>
|
|
167
182
|
<div>
|
|
168
|
-
<NuxtTime
|
|
169
|
-
|
|
170
|
-
|
|
183
|
+
<NuxtTime
|
|
184
|
+
:datetime="Date.now()"
|
|
185
|
+
locale="en-US"
|
|
186
|
+
weekday="long"
|
|
187
|
+
/>
|
|
188
|
+
<NuxtTime
|
|
189
|
+
:datetime="Date.now()"
|
|
190
|
+
locale="fr-FR"
|
|
191
|
+
weekday="long"
|
|
192
|
+
/>
|
|
193
|
+
<NuxtTime
|
|
194
|
+
:datetime="Date.now()"
|
|
195
|
+
locale="ja-JP"
|
|
196
|
+
weekday="long"
|
|
197
|
+
/>
|
|
171
198
|
</div>
|
|
172
199
|
</template>
|
|
173
200
|
```
|
|
@@ -18,7 +18,7 @@ links:
|
|
|
18
18
|
|
|
19
19
|
```vue
|
|
20
20
|
<template>
|
|
21
|
-
<RouterView
|
|
21
|
+
<RouterView v-slot="{ Component }">
|
|
22
22
|
<!-- Optional, when using transitions -->
|
|
23
23
|
<Transition>
|
|
24
24
|
<!-- Optional, when using keep-alive -->
|
|
@@ -84,7 +84,7 @@ Alternatively, `pageKey` can be passed as a `key` value via [`definePageMeta`](/
|
|
|
84
84
|
```vue [app/pages/my-page.vue]
|
|
85
85
|
<script setup lang="ts">
|
|
86
86
|
definePageMeta({
|
|
87
|
-
key: route => route.fullPath
|
|
87
|
+
key: route => route.fullPath,
|
|
88
88
|
})
|
|
89
89
|
</script>
|
|
90
90
|
```
|
|
@@ -66,8 +66,11 @@ Read more about dynamic layouts.
|
|
|
66
66
|
```vue [app/pages/some-page.vue]
|
|
67
67
|
<template>
|
|
68
68
|
<div>
|
|
69
|
-
<NuxtLayout
|
|
70
|
-
|
|
69
|
+
<NuxtLayout
|
|
70
|
+
name="custom"
|
|
71
|
+
title="I am a custom layout"
|
|
72
|
+
>
|
|
73
|
+
<!-- ... -->
|
|
71
74
|
</NuxtLayout>
|
|
72
75
|
</div>
|
|
73
76
|
</template>
|
|
@@ -93,7 +96,9 @@ console.log(layoutCustomProps.title) // I am a custom layout
|
|
|
93
96
|
<template>
|
|
94
97
|
<div>
|
|
95
98
|
<NuxtLayout name="custom">
|
|
96
|
-
<template #header>
|
|
99
|
+
<template #header>
|
|
100
|
+
Some header template content.
|
|
101
|
+
</template>
|
|
97
102
|
</NuxtLayout>
|
|
98
103
|
</div>
|
|
99
104
|
</template>
|
|
@@ -139,7 +144,7 @@ function logFoo () {
|
|
|
139
144
|
<script setup lang="ts">
|
|
140
145
|
const foo = () => console.log('foo')
|
|
141
146
|
defineExpose({
|
|
142
|
-
foo
|
|
147
|
+
foo,
|
|
143
148
|
})
|
|
144
149
|
</script>
|
|
145
150
|
|
|
@@ -67,7 +67,10 @@ For static files in the `/public` directory, such as PDFs or images, use the `ex
|
|
|
67
67
|
|
|
68
68
|
```vue [app/pages/index.vue]
|
|
69
69
|
<template>
|
|
70
|
-
<NuxtLink
|
|
70
|
+
<NuxtLink
|
|
71
|
+
to="/example-report.pdf"
|
|
72
|
+
external
|
|
73
|
+
>
|
|
71
74
|
Download Report
|
|
72
75
|
</NuxtLink>
|
|
73
76
|
</template>
|
|
@@ -79,7 +82,10 @@ When pointing to a different application on the same domain, using the `external
|
|
|
79
82
|
|
|
80
83
|
```vue [app/pages/index.vue]
|
|
81
84
|
<template>
|
|
82
|
-
<NuxtLink
|
|
85
|
+
<NuxtLink
|
|
86
|
+
to="/another-app"
|
|
87
|
+
external
|
|
88
|
+
>
|
|
83
89
|
Go to Another App
|
|
84
90
|
</NuxtLink>
|
|
85
91
|
</template>
|
|
@@ -117,12 +123,18 @@ When you need to overwrite this behavior you can use the `rel` or `noRel` props.
|
|
|
117
123
|
</NuxtLink>
|
|
118
124
|
<!-- <a href="https://twitter.com/nuxt_js" rel="noopener noreferrer">...</a> -->
|
|
119
125
|
|
|
120
|
-
<NuxtLink
|
|
126
|
+
<NuxtLink
|
|
127
|
+
to="https://discord.nuxtjs.org"
|
|
128
|
+
rel="noopener"
|
|
129
|
+
>
|
|
121
130
|
Nuxt Discord
|
|
122
131
|
</NuxtLink>
|
|
123
132
|
<!-- <a href="https://discord.nuxtjs.org" rel="noopener">...</a> -->
|
|
124
133
|
|
|
125
|
-
<NuxtLink
|
|
134
|
+
<NuxtLink
|
|
135
|
+
to="/about"
|
|
136
|
+
target="_blank"
|
|
137
|
+
>About page</NuxtLink>
|
|
126
138
|
<!-- <a href="/about" target="_blank" rel="noopener noreferrer">...</a> -->
|
|
127
139
|
</template>
|
|
128
140
|
```
|
|
@@ -131,7 +143,10 @@ A `noRel` prop can be used to prevent the default `rel` attribute from being add
|
|
|
131
143
|
|
|
132
144
|
```vue [app/app.vue]
|
|
133
145
|
<template>
|
|
134
|
-
<NuxtLink
|
|
146
|
+
<NuxtLink
|
|
147
|
+
to="https://github.com/nuxt"
|
|
148
|
+
no-rel
|
|
149
|
+
>
|
|
135
150
|
Nuxt GitHub
|
|
136
151
|
</NuxtLink>
|
|
137
152
|
<!-- <a href="https://github.com/nuxt">...</a> -->
|
|
@@ -147,8 +162,13 @@ A `noRel` prop can be used to prevent the default `rel` attribute from being add
|
|
|
147
162
|
Nuxt automatically includes smart prefetching. That means it detects when a link is visible (by default), either in the viewport or when scrolling and prefetches the JavaScript for those pages so that they are ready when the user clicks the link. Nuxt only loads the resources when the browser isn't busy and skips prefetching if your connection is offline or if you only have 2g connection.
|
|
148
163
|
|
|
149
164
|
```vue [app/pages/index.vue]
|
|
150
|
-
<NuxtLink to="/about" no-prefetch>
|
|
151
|
-
|
|
165
|
+
<NuxtLink to="/about" no-prefetch>
|
|
166
|
+
About page not pre-fetched
|
|
167
|
+
</NuxtLink>
|
|
168
|
+
|
|
169
|
+
<NuxtLink to="/about" :prefetch="false">
|
|
170
|
+
About page not pre-fetched
|
|
171
|
+
</NuxtLink>
|
|
152
172
|
```
|
|
153
173
|
|
|
154
174
|
### Custom Prefetch Triggers
|
|
@@ -273,12 +293,12 @@ export default defineNuxtConfig({
|
|
|
273
293
|
activeClass: 'router-link-active',
|
|
274
294
|
exactActiveClass: 'router-link-exact-active',
|
|
275
295
|
prefetchedClass: undefined, // can be any valid string class name
|
|
276
|
-
trailingSlash: undefined // can be 'append' or 'remove'
|
|
296
|
+
trailingSlash: undefined, // can be 'append' or 'remove'
|
|
277
297
|
prefetch: true,
|
|
278
|
-
prefetchOn: { visibility: true }
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}
|
|
298
|
+
prefetchOn: { visibility: true },
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
},
|
|
282
302
|
})
|
|
283
303
|
```
|
|
284
304
|
|
|
@@ -286,7 +306,7 @@ export default defineNuxtConfig({
|
|
|
286
306
|
|
|
287
307
|
You can overwrite `<NuxtLink>` defaults by creating your own link component using `defineNuxtLink`.
|
|
288
308
|
|
|
289
|
-
```
|
|
309
|
+
```ts [app/components/MyNuxtLink.ts]
|
|
290
310
|
export default defineNuxtLink({
|
|
291
311
|
componentName: 'MyNuxtLink',
|
|
292
312
|
/* see signature below for more */
|
|
@@ -299,10 +319,10 @@ You can then use `<MyNuxtLink />` component as usual with your new defaults.
|
|
|
299
319
|
|
|
300
320
|
```ts
|
|
301
321
|
interface NuxtLinkOptions {
|
|
302
|
-
componentName?: string
|
|
303
|
-
externalRelAttribute?: string
|
|
304
|
-
activeClass?: string
|
|
305
|
-
exactActiveClass?: string
|
|
322
|
+
componentName?: string
|
|
323
|
+
externalRelAttribute?: string
|
|
324
|
+
activeClass?: string
|
|
325
|
+
exactActiveClass?: string
|
|
306
326
|
trailingSlash?: 'append' | 'remove'
|
|
307
327
|
prefetch?: boolean
|
|
308
328
|
prefetchedClass?: string
|
|
@@ -311,7 +331,7 @@ interface NuxtLinkOptions {
|
|
|
311
331
|
interaction: boolean
|
|
312
332
|
}>
|
|
313
333
|
}
|
|
314
|
-
function defineNuxtLink(options: NuxtLinkOptions): Component {}
|
|
334
|
+
function defineNuxtLink (options: NuxtLinkOptions): Component {}
|
|
315
335
|
```
|
|
316
336
|
|
|
317
337
|
- `componentName`: A name for the component. Default is `NuxtLink`.
|
|
@@ -29,16 +29,18 @@ The `<NuxtErrorBoundary>` uses Vue's [`onErrorCaptured`](https://vuejs.org/api/c
|
|
|
29
29
|
- `#error`: Specify a fallback content to display in case of error.
|
|
30
30
|
|
|
31
31
|
```vue
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
<template>
|
|
33
|
+
<NuxtErrorBoundary>
|
|
34
|
+
<!-- ... -->
|
|
35
|
+
<template #error="{ error, clearError }">
|
|
36
|
+
<p>An error occurred: {{ error }}</p>
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
<button @click="clearError">
|
|
39
|
+
Clear error
|
|
40
|
+
</button>
|
|
41
|
+
</template>
|
|
42
|
+
</NuxtErrorBoundary>
|
|
43
|
+
</template>
|
|
42
44
|
```
|
|
43
45
|
|
|
44
46
|
:read-more{to="/docs/4.x/getting-started/error-handling"}
|
|
@@ -24,8 +24,8 @@ Call `onPrehydrate` in the setup function of a Vue component (e.g., in `<script
|
|
|
24
24
|
## Type
|
|
25
25
|
|
|
26
26
|
```ts [Signature]
|
|
27
|
-
export function onPrehydrate(callback: (el: HTMLElement) => void): void
|
|
28
|
-
export function onPrehydrate(callback: string | ((el: HTMLElement) => void), key?: string): undefined | string
|
|
27
|
+
export function onPrehydrate (callback: (el: HTMLElement) => void): void
|
|
28
|
+
export function onPrehydrate (callback: string | ((el: HTMLElement) => void), key?: string): undefined | string
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
## Parameters
|
|
@@ -20,7 +20,7 @@ Within your pages, components, and plugins you can use useAsyncData to get acces
|
|
|
20
20
|
<script setup lang="ts">
|
|
21
21
|
const { data, status, error, refresh, clear } = await useAsyncData(
|
|
22
22
|
'mountains',
|
|
23
|
-
() => $fetch('https://api.nuxtjs.dev/mountains')
|
|
23
|
+
() => $fetch('https://api.nuxtjs.dev/mountains'),
|
|
24
24
|
)
|
|
25
25
|
</script>
|
|
26
26
|
```
|
|
@@ -44,11 +44,11 @@ const { data: posts } = await useAsyncData(
|
|
|
44
44
|
'posts',
|
|
45
45
|
() => $fetch('https://fakeApi.com/posts', {
|
|
46
46
|
params: {
|
|
47
|
-
page: page.value
|
|
48
|
-
}
|
|
47
|
+
page: page.value,
|
|
48
|
+
},
|
|
49
49
|
}), {
|
|
50
|
-
watch: [page]
|
|
51
|
-
}
|
|
50
|
+
watch: [page],
|
|
51
|
+
},
|
|
52
52
|
)
|
|
53
53
|
</script>
|
|
54
54
|
```
|
|
@@ -65,7 +65,7 @@ const userId = computed(() => `user-${route.params.id}`)
|
|
|
65
65
|
// When the route changes and userId updates, the data will be automatically refetched
|
|
66
66
|
const { data: user } = useAsyncData(
|
|
67
67
|
userId,
|
|
68
|
-
() => fetchUserById(route.params.id)
|
|
68
|
+
() => fetchUserById(route.params.id),
|
|
69
69
|
)
|
|
70
70
|
</script>
|
|
71
71
|
```
|
|
@@ -91,8 +91,8 @@ The `handler` function should be **side-effect free** to ensure predictable beha
|
|
|
91
91
|
- `transform`: a function that can be used to alter `handler` function result after resolving
|
|
92
92
|
- `getCachedData`: Provide a function which returns cached data. A `null` or `undefined` return value will trigger a fetch. By default, this is:
|
|
93
93
|
```ts
|
|
94
|
-
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
95
|
-
? nuxtApp.payload.data[key]
|
|
94
|
+
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
95
|
+
? nuxtApp.payload.data[key]
|
|
96
96
|
: nuxtApp.static.data[key]
|
|
97
97
|
```
|
|
98
98
|
Which only caches data when `experimental.payloadExtraction` of `nuxt.config` is enabled.
|
|
@@ -169,11 +169,11 @@ If you have not fetched data on the server (for example, with `server: false`),
|
|
|
169
169
|
## Type
|
|
170
170
|
|
|
171
171
|
```ts [Signature]
|
|
172
|
-
function useAsyncData<DataT, DataE>(
|
|
172
|
+
export function useAsyncData<DataT, DataE> (
|
|
173
173
|
handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
|
|
174
174
|
options?: AsyncDataOptions<DataT>
|
|
175
175
|
): AsyncData<DataT, DataE>
|
|
176
|
-
function useAsyncData<DataT, DataE>(
|
|
176
|
+
export function useAsyncData<DataT, DataE> (
|
|
177
177
|
key: MaybeRefOrGetter<string>,
|
|
178
178
|
handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
|
|
179
179
|
options?: AsyncDataOptions<DataT>
|
|
@@ -204,7 +204,7 @@ type AsyncData<DataT, ErrorT> = {
|
|
|
204
204
|
clear: () => void
|
|
205
205
|
error: Ref<ErrorT | undefined>
|
|
206
206
|
status: Ref<AsyncDataRequestStatus>
|
|
207
|
-
}
|
|
207
|
+
}
|
|
208
208
|
|
|
209
209
|
interface AsyncDataExecuteOptions {
|
|
210
210
|
dedupe?: 'cancel' | 'defer'
|
|
@@ -40,7 +40,7 @@ export interface CookieOptions<T = any> extends Omit<CookieSerializeOptions & Co
|
|
|
40
40
|
|
|
41
41
|
export interface CookieRef<T> extends Ref<T> {}
|
|
42
42
|
|
|
43
|
-
export function useCookie<T = string | null | undefined>(
|
|
43
|
+
export function useCookie<T = string | null | undefined> (
|
|
44
44
|
name: string,
|
|
45
45
|
options?: CookieOptions<T>
|
|
46
46
|
): CookieRef<T>
|
|
@@ -84,15 +84,21 @@ The example below creates a cookie called `counter`. If the cookie doesn't exist
|
|
|
84
84
|
<script setup lang="ts">
|
|
85
85
|
const counter = useCookie('counter')
|
|
86
86
|
|
|
87
|
-
counter.value
|
|
87
|
+
counter.value ||= Math.round(Math.random() * 1000)
|
|
88
88
|
</script>
|
|
89
89
|
|
|
90
90
|
<template>
|
|
91
91
|
<div>
|
|
92
92
|
<h1>Counter: {{ counter || '-' }}</h1>
|
|
93
|
-
<button @click="counter = null">
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
<button @click="counter = null">
|
|
94
|
+
reset
|
|
95
|
+
</button>
|
|
96
|
+
<button @click="counter--">
|
|
97
|
+
-
|
|
98
|
+
</button>
|
|
99
|
+
<button @click="counter++">
|
|
100
|
+
+
|
|
101
|
+
</button>
|
|
96
102
|
</div>
|
|
97
103
|
</template>
|
|
98
104
|
```
|
|
@@ -105,8 +111,8 @@ const user = useCookie(
|
|
|
105
111
|
'userInfo',
|
|
106
112
|
{
|
|
107
113
|
default: () => ({ score: -1 }),
|
|
108
|
-
watch: false
|
|
109
|
-
}
|
|
114
|
+
watch: false,
|
|
115
|
+
},
|
|
110
116
|
)
|
|
111
117
|
|
|
112
118
|
if (user.value) {
|
|
@@ -128,20 +134,18 @@ const list = useCookie(
|
|
|
128
134
|
'list',
|
|
129
135
|
{
|
|
130
136
|
default: () => [],
|
|
131
|
-
watch: 'shallow'
|
|
132
|
-
}
|
|
137
|
+
watch: 'shallow',
|
|
138
|
+
},
|
|
133
139
|
)
|
|
134
140
|
|
|
135
|
-
function add() {
|
|
141
|
+
function add () {
|
|
136
142
|
list.value?.push(Math.round(Math.random() * 1000))
|
|
137
143
|
// list cookie won't be updated with this change
|
|
138
144
|
}
|
|
139
145
|
|
|
140
|
-
function save() {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
list.value = [...list.value]
|
|
144
|
-
}
|
|
146
|
+
function save () {
|
|
147
|
+
// the actual `list` cookie will be updated
|
|
148
|
+
list.value &&= [...list.value]
|
|
145
149
|
}
|
|
146
150
|
</script>
|
|
147
151
|
|
|
@@ -149,8 +153,12 @@ function save() {
|
|
|
149
153
|
<div>
|
|
150
154
|
<h1>List</h1>
|
|
151
155
|
<pre>{{ list }}</pre>
|
|
152
|
-
<button @click="add">
|
|
153
|
-
|
|
156
|
+
<button @click="add">
|
|
157
|
+
Add
|
|
158
|
+
</button>
|
|
159
|
+
<button @click="save">
|
|
160
|
+
Save
|
|
161
|
+
</button>
|
|
154
162
|
</div>
|
|
155
163
|
</template>
|
|
156
164
|
```
|
|
@@ -160,7 +168,7 @@ function save() {
|
|
|
160
168
|
You can use `getCookie` and `setCookie` from [`h3`](https://github.com/h3js/h3) package to set cookies in server API routes.
|
|
161
169
|
|
|
162
170
|
```ts [server/api/counter.ts]
|
|
163
|
-
export default defineEventHandler(event => {
|
|
171
|
+
export default defineEventHandler((event) => {
|
|
164
172
|
// Read counter cookie
|
|
165
173
|
let counter = getCookie(event, 'counter') || 0
|
|
166
174
|
|
|
@@ -20,7 +20,7 @@ It automatically generates a key based on URL and fetch options, provides type h
|
|
|
20
20
|
```vue [app/pages/modules.vue]
|
|
21
21
|
<script setup lang="ts">
|
|
22
22
|
const { data, status, error, refresh, clear } = await useFetch('/api/modules', {
|
|
23
|
-
pick: ['title']
|
|
23
|
+
pick: ['title'],
|
|
24
24
|
})
|
|
25
25
|
</script>
|
|
26
26
|
```
|
|
@@ -38,7 +38,7 @@ Using the `query` option, you can add search parameters to your query. This opti
|
|
|
38
38
|
```ts
|
|
39
39
|
const param1 = ref('value1')
|
|
40
40
|
const { data, status, error, refresh } = await useFetch('/api/modules', {
|
|
41
|
-
query: { param1, param2: 'value2' }
|
|
41
|
+
query: { param1, param2: 'value2' },
|
|
42
42
|
})
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -48,21 +48,21 @@ You can also use [interceptors](https://github.com/unjs/ofetch#%EF%B8%8F-interce
|
|
|
48
48
|
|
|
49
49
|
```ts
|
|
50
50
|
const { data, status, error, refresh, clear } = await useFetch('/api/auth/login', {
|
|
51
|
-
onRequest({ request, options }) {
|
|
51
|
+
onRequest ({ request, options }) {
|
|
52
52
|
// Set the request headers
|
|
53
53
|
// note that this relies on ofetch >= 1.4.0 - you may need to refresh your lockfile
|
|
54
54
|
options.headers.set('Authorization', '...')
|
|
55
55
|
},
|
|
56
|
-
onRequestError({ request, options, error }) {
|
|
56
|
+
onRequestError ({ request, options, error }) {
|
|
57
57
|
// Handle the request errors
|
|
58
58
|
},
|
|
59
|
-
onResponse({ request, response, options }) {
|
|
59
|
+
onResponse ({ request, response, options }) {
|
|
60
60
|
// Process the response data
|
|
61
61
|
localStorage.setItem('token', response._data.token)
|
|
62
62
|
},
|
|
63
|
-
onResponseError({ request, response, options }) {
|
|
63
|
+
onResponseError ({ request, response, options }) {
|
|
64
64
|
// Handle the response errors
|
|
65
|
-
}
|
|
65
|
+
},
|
|
66
66
|
})
|
|
67
67
|
```
|
|
68
68
|
|
|
@@ -105,7 +105,7 @@ Fetch options can be provided as reactive, supporting `computed`, `ref` and [com
|
|
|
105
105
|
```ts
|
|
106
106
|
const searchQuery = ref('initial')
|
|
107
107
|
const { data } = await useFetch('/api/search', {
|
|
108
|
-
query: { q: searchQuery }
|
|
108
|
+
query: { q: searchQuery },
|
|
109
109
|
})
|
|
110
110
|
// triggers a refetch: /api/search?q=new%20search
|
|
111
111
|
searchQuery.value = 'new search'
|
|
@@ -117,7 +117,7 @@ If needed, you can opt out of this behavior using `watch: false`:
|
|
|
117
117
|
const searchQuery = ref('initial')
|
|
118
118
|
const { data } = await useFetch('/api/search', {
|
|
119
119
|
query: { q: searchQuery },
|
|
120
|
-
watch: false
|
|
120
|
+
watch: false,
|
|
121
121
|
})
|
|
122
122
|
// does not trigger a refetch
|
|
123
123
|
searchQuery.value = 'new search'
|
|
@@ -126,7 +126,7 @@ searchQuery.value = 'new search'
|
|
|
126
126
|
## Type
|
|
127
127
|
|
|
128
128
|
```ts [Signature]
|
|
129
|
-
function useFetch<DataT, ErrorT>(
|
|
129
|
+
export function useFetch<DataT, ErrorT> (
|
|
130
130
|
url: string | Request | Ref<string | Request> | (() => string | Request),
|
|
131
131
|
options?: UseFetchOptions<DataT>
|
|
132
132
|
): Promise<AsyncData<DataT, ErrorT>>
|
|
@@ -210,9 +210,9 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
|
|
210
210
|
**getCachedData default:**
|
|
211
211
|
|
|
212
212
|
```ts
|
|
213
|
-
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
214
|
-
|
|
215
|
-
|
|
213
|
+
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
214
|
+
? nuxtApp.payload.data[key]
|
|
215
|
+
: nuxtApp.static.data[key]
|
|
216
216
|
```
|
|
217
217
|
This only caches data when `experimental.payloadExtraction` in `nuxt.config` is enabled.
|
|
218
218
|
|
|
@@ -17,11 +17,11 @@ You can pass all the same values as [`useHead`](/docs/4.x/api/composables/use-he
|
|
|
17
17
|
```ts
|
|
18
18
|
useHeadSafe({
|
|
19
19
|
script: [
|
|
20
|
-
{ id: 'xss-script', innerHTML: 'alert("xss")' }
|
|
20
|
+
{ id: 'xss-script', innerHTML: 'alert("xss")' },
|
|
21
21
|
],
|
|
22
22
|
meta: [
|
|
23
|
-
{ 'http-equiv': 'refresh', content: '0;javascript:alert(1)' }
|
|
24
|
-
]
|
|
23
|
+
{ 'http-equiv': 'refresh', 'content': '0;javascript:alert(1)' },
|
|
24
|
+
],
|
|
25
25
|
})
|
|
26
26
|
// Will safely generate
|
|
27
27
|
// <script id="xss-script"></script>
|
|
@@ -34,8 +34,8 @@ Read more on the `Unhead` documentation.
|
|
|
34
34
|
|
|
35
35
|
## Type
|
|
36
36
|
|
|
37
|
-
```ts
|
|
38
|
-
useHeadSafe(input: MaybeComputedRef<HeadSafe>): void
|
|
37
|
+
```ts [Signature]
|
|
38
|
+
export function useHeadSafe (input: MaybeComputedRef<HeadSafe>): void
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
The list of allowed values is:
|
|
@@ -14,8 +14,8 @@ The [`useHead`](/docs/4.x/api/composables/use-head) composable function allows y
|
|
|
14
14
|
|
|
15
15
|
## Type
|
|
16
16
|
|
|
17
|
-
```ts
|
|
18
|
-
useHead(meta: MaybeComputedRef<MetaObject>): void
|
|
17
|
+
```ts [Signature]
|
|
18
|
+
export function useHead (meta: MaybeComputedRef<MetaObject>): void
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
Below are the non-reactive types for [`useHead`](/docs/4.x/api/composables/use-head) .
|
|
@@ -47,9 +47,9 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
47
|
const myStore = new MyStore()
|
|
48
48
|
|
|
49
49
|
useHydration(
|
|
50
|
-
'myStoreState',
|
|
51
|
-
() => myStore.getState(),
|
|
52
|
-
|
|
50
|
+
'myStoreState',
|
|
51
|
+
() => myStore.getState(),
|
|
52
|
+
data => myStore.setState(data),
|
|
53
53
|
)
|
|
54
54
|
})
|
|
55
55
|
```
|
|
@@ -57,8 +57,8 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
57
57
|
|
|
58
58
|
## Type
|
|
59
59
|
|
|
60
|
-
```ts [
|
|
61
|
-
useHydration
|
|
60
|
+
```ts [Signature]
|
|
61
|
+
export function useHydration<T> (key: string, get: () => T, set: (value: T) => void): void
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
## Parameters
|