@nuxt/docs 4.1.2 → 4.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/1.getting-started/01.introduction.md +6 -6
- package/1.getting-started/02.installation.md +2 -1
- package/1.getting-started/03.configuration.md +36 -36
- package/1.getting-started/04.views.md +9 -9
- package/1.getting-started/05.assets.md +15 -9
- package/1.getting-started/06.styling.md +58 -48
- package/1.getting-started/07.routing.md +17 -17
- package/1.getting-started/08.seo-meta.md +59 -46
- package/1.getting-started/09.transitions.md +49 -44
- package/1.getting-started/10.data-fetching.md +104 -81
- package/1.getting-started/11.state-management.md +26 -19
- package/1.getting-started/12.error-handling.md +22 -20
- package/1.getting-started/13.server.md +8 -8
- package/1.getting-started/14.layers.md +22 -16
- package/1.getting-started/15.prerendering.md +32 -32
- package/1.getting-started/16.deployment.md +10 -10
- package/1.getting-started/17.testing.md +44 -44
- package/1.getting-started/18.upgrade.md +53 -71
- package/2.guide/0.index.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/0.nuxt.md +3 -3
- package/2.guide/1.directory-structure/0.output.md +18 -0
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/.navigation.yml +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.assets.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.components.md +45 -28
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.composables.md +13 -13
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.layouts.md +19 -15
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.middleware.md +31 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.pages.md +39 -37
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.plugins.md +25 -25
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/1.utils.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app-config.md +18 -18
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.app.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.app/3.error.md +6 -6
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.content.md +7 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.modules.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.node_modules.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.public.md +2 -2
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.server.md +35 -35
- package/2.guide/{2.directory-structure → 1.directory-structure}/1.shared.md +7 -7
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.env.md +8 -8
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.gitignore.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtignore.md +5 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/2.nuxtrc.md +4 -4
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.nuxt-config.md +3 -3
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.package.md +1 -1
- package/2.guide/{2.directory-structure → 1.directory-structure}/3.tsconfig.md +3 -3
- package/2.guide/{1.concepts → 2.concepts}/1.auto-imports.md +22 -22
- package/2.guide/{1.concepts → 2.concepts}/10.nuxt-lifecycle.md +17 -17
- package/2.guide/{1.concepts → 2.concepts}/2.vuejs-development.md +13 -13
- package/2.guide/{1.concepts → 2.concepts}/3.rendering.md +24 -22
- package/2.guide/{1.concepts → 2.concepts}/4.server-engine.md +6 -6
- package/2.guide/{1.concepts → 2.concepts}/5.modules.md +5 -5
- package/2.guide/{1.concepts → 2.concepts}/7.esm.md +17 -15
- package/2.guide/{1.concepts → 2.concepts}/8.typescript.md +12 -12
- package/2.guide/3.going-further/1.events.md +3 -3
- package/2.guide/3.going-further/1.experimental-features.md +246 -85
- package/2.guide/3.going-further/1.features.md +44 -9
- package/2.guide/3.going-further/1.internals.md +25 -25
- package/2.guide/3.going-further/10.runtime-config.md +12 -12
- package/2.guide/3.going-further/11.nightly-release-channel.md +1 -1
- package/2.guide/3.going-further/2.hooks.md +14 -14
- package/2.guide/3.going-further/3.modules.md +96 -94
- package/2.guide/3.going-further/4.kit.md +7 -7
- package/2.guide/3.going-further/6.nuxt-app.md +8 -8
- package/2.guide/3.going-further/7.layers.md +62 -53
- package/2.guide/3.going-further/9.debugging.md +2 -2
- package/2.guide/4.recipes/1.custom-routing.md +30 -30
- package/2.guide/4.recipes/2.vite-plugin.md +4 -4
- package/2.guide/4.recipes/3.custom-usefetch.md +13 -13
- package/2.guide/4.recipes/4.sessions-and-authentication.md +35 -21
- package/2.guide/5.best-practices/hydration.md +4 -4
- package/2.guide/5.best-practices/performance.md +17 -17
- 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/10.nuxt-picture.md +1 -1
- package/3.api/1.components/11.teleports.md +5 -2
- package/3.api/1.components/12.nuxt-route-announcer.md +9 -9
- package/3.api/1.components/13.nuxt-time.md +44 -17
- package/3.api/1.components/2.nuxt-page.md +6 -6
- package/3.api/1.components/3.nuxt-layout.md +15 -10
- package/3.api/1.components/4.nuxt-link.md +42 -22
- package/3.api/1.components/5.nuxt-loading-indicator.md +3 -3
- 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 +20 -20
- package/3.api/2.composables/use-cookie.md +29 -21
- package/3.api/2.composables/use-error.md +2 -2
- package/3.api/2.composables/use-fetch.md +58 -32
- package/3.api/2.composables/use-head-safe.md +7 -7
- package/3.api/2.composables/use-head.md +5 -5
- package/3.api/2.composables/use-hydration.md +6 -6
- package/3.api/2.composables/use-lazy-async-data.md +4 -4
- package/3.api/2.composables/use-lazy-fetch.md +4 -4
- package/3.api/2.composables/use-loading-indicator.md +12 -12
- package/3.api/2.composables/use-nuxt-app.md +22 -22
- package/3.api/2.composables/use-nuxt-data.md +8 -8
- package/3.api/2.composables/use-preview-mode.md +15 -18
- package/3.api/2.composables/use-request-event.md +1 -1
- package/3.api/2.composables/use-request-fetch.md +3 -3
- package/3.api/2.composables/use-request-header.md +1 -1
- package/3.api/2.composables/use-request-headers.md +4 -4
- package/3.api/2.composables/use-request-url.md +1 -1
- package/3.api/2.composables/use-response-header.md +9 -10
- package/3.api/2.composables/use-route-announcer.md +4 -4
- package/3.api/2.composables/use-route.md +1 -1
- package/3.api/2.composables/use-router.md +10 -8
- package/3.api/2.composables/use-runtime-config.md +11 -11
- package/3.api/2.composables/use-runtime-hook.md +2 -2
- package/3.api/2.composables/use-seo-meta.md +4 -4
- package/3.api/2.composables/use-server-seo-meta.md +6 -6
- package/3.api/2.composables/use-state.md +5 -5
- package/3.api/3.utils/$fetch.md +10 -8
- package/3.api/3.utils/abort-navigation.md +3 -3
- package/3.api/3.utils/add-route-middleware.md +5 -5
- package/3.api/3.utils/call-once.md +6 -6
- package/3.api/3.utils/clear-error.md +3 -3
- package/3.api/3.utils/clear-nuxt-data.md +3 -3
- package/3.api/3.utils/clear-nuxt-state.md +3 -3
- package/3.api/3.utils/create-error.md +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 +13 -13
- package/3.api/3.utils/define-nuxt-route-middleware.md +5 -5
- package/3.api/3.utils/define-page-meta.md +23 -23
- package/3.api/3.utils/define-route-rules.md +7 -7
- package/3.api/3.utils/navigate-to.md +11 -11
- package/3.api/3.utils/prefetch-components.md +1 -1
- package/3.api/3.utils/preload-components.md +1 -1
- package/3.api/3.utils/preload-route-components.md +2 -2
- package/3.api/3.utils/prerender-routes.md +3 -3
- package/3.api/3.utils/refresh-cookie.md +4 -4
- package/3.api/3.utils/refresh-nuxt-data.md +12 -7
- package/3.api/3.utils/reload-nuxt-app.md +3 -3
- package/3.api/3.utils/set-page-layout.md +1 -1
- package/3.api/3.utils/set-response-status.md +3 -3
- package/3.api/3.utils/show-error.md +5 -5
- package/3.api/3.utils/update-app-config.md +4 -3
- package/3.api/4.commands/add.md +1 -1
- package/3.api/4.commands/analyze.md +2 -1
- package/3.api/4.commands/build.md +2 -1
- package/3.api/4.commands/dev.md +5 -4
- package/3.api/4.commands/generate.md +3 -2
- package/3.api/4.commands/init.md +3 -2
- package/3.api/4.commands/module.md +4 -4
- package/3.api/4.commands/prepare.md +7 -2
- package/3.api/4.commands/preview.md +5 -4
- package/3.api/4.commands/test.md +40 -0
- package/3.api/4.commands/typecheck.md +5 -3
- package/3.api/4.commands/upgrade.md +3 -3
- package/3.api/5.kit/1.modules.md +36 -36
- package/3.api/5.kit/10.runtime-config.md +1 -1
- package/3.api/5.kit/10.templates.md +8 -6
- package/3.api/5.kit/11.nitro.md +62 -62
- package/3.api/5.kit/12.resolving.md +2 -2
- package/3.api/5.kit/14.builder.md +1 -0
- package/3.api/5.kit/15.examples.md +2 -2
- package/3.api/5.kit/16.layers.md +26 -26
- package/3.api/5.kit/3.compatibility.md +14 -14
- package/3.api/5.kit/4.autoimports.md +13 -13
- package/3.api/5.kit/5.components.md +7 -7
- package/3.api/5.kit/6.context.md +3 -3
- package/3.api/5.kit/7.pages.md +7 -7
- package/3.api/5.kit/8.layout.md +2 -2
- package/3.api/5.kit/9.plugins.md +5 -4
- package/3.api/6.advanced/1.hooks.md +3 -3
- package/3.api/6.advanced/2.import-meta.md +3 -3
- package/3.api/6.nuxt-config.md +300 -865
- package/3.api/index.md +7 -7
- package/5.community/2.getting-help.md +1 -1
- package/5.community/3.reporting-bugs.md +1 -1
- package/5.community/4.contribution.md +11 -11
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +1 -1
- package/6.bridge/1.overview.md +13 -13
- package/6.bridge/10.configuration.md +2 -1
- package/6.bridge/2.typescript.md +3 -3
- package/6.bridge/3.bridge-composition-api.md +8 -8
- package/6.bridge/4.plugins-and-middleware.md +9 -9
- package/6.bridge/5.nuxt3-compatible-api.md +20 -17
- package/6.bridge/6.meta.md +20 -19
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +3 -3
- package/6.bridge/9.vite.md +4 -4
- package/7.migration/1.overview.md +2 -2
- package/7.migration/10.bundling.md +1 -1
- package/7.migration/11.server.md +3 -3
- package/7.migration/2.configuration.md +23 -21
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +21 -18
- package/7.migration/5.plugins-and-middleware.md +8 -8
- package/7.migration/6.pages-and-layouts.md +28 -24
- package/7.migration/7.component-options.md +18 -18
- package/7.migration/8.runtime-config.md +7 -7
- package/package.json +1 -1
- package/2.guide/2.directory-structure/0.output.md +0 -18
- /package/2.guide/{1.concepts → 2.concepts}/.navigation.yml +0 -0
- /package/2.guide/{1.concepts → 2.concepts}/9.code-style.md +0 -0
|
@@ -29,19 +29,21 @@ 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
|
-
:read-more{to="/docs/getting-started/error-handling"}
|
|
46
|
+
:read-more{to="/docs/4.x/getting-started/error-handling"}
|
|
45
47
|
|
|
46
48
|
## Examples
|
|
47
49
|
|
|
@@ -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
|
|
@@ -11,7 +11,7 @@ links:
|
|
|
11
11
|
Within your pages, components, and plugins you can use useAsyncData to get access to data that resolves asynchronously.
|
|
12
12
|
|
|
13
13
|
::note
|
|
14
|
-
[`useAsyncData`](/docs/api/composables/use-async-data) is a composable meant to be called directly in the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context). It returns reactive composables and handles adding responses to the Nuxt payload so they can be passed from server to client **without re-fetching the data on client side** when the page hydrates.
|
|
14
|
+
[`useAsyncData`](/docs/4.x/api/composables/use-async-data) is a composable meant to be called directly in the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context). It returns reactive composables and handles adding responses to the Nuxt payload so they can be passed from server to client **without re-fetching the data on client side** when the page hydrates.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
17
|
## Usage
|
|
@@ -20,13 +20,13 @@ 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
|
```
|
|
27
27
|
|
|
28
28
|
::warning
|
|
29
|
-
If you're using a custom useAsyncData wrapper, do not await it in the composable, as that can cause unexpected behavior. Please follow [this recipe](/docs/guide/recipes/custom-usefetch#custom-
|
|
29
|
+
If you're using a custom useAsyncData wrapper, do not await it in the composable, as that can cause unexpected behavior. Please follow [this recipe](/docs/4.x/guide/recipes/custom-usefetch#custom-usefetchuseasyncdata) for more information on how to make a custom async data fetcher.
|
|
30
30
|
::
|
|
31
31
|
|
|
32
32
|
::note
|
|
@@ -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,23 +65,23 @@ 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
|
```
|
|
72
72
|
|
|
73
73
|
::warning
|
|
74
|
-
[`useAsyncData`](/docs/api/composables/use-async-data) is a reserved function name transformed by the compiler, so you should not name your own function [`useAsyncData`](/docs/api/composables/use-async-data).
|
|
74
|
+
[`useAsyncData`](/docs/4.x/api/composables/use-async-data) is a reserved function name transformed by the compiler, so you should not name your own function [`useAsyncData`](/docs/4.x/api/composables/use-async-data).
|
|
75
75
|
::
|
|
76
76
|
|
|
77
|
-
:read-more{to="/docs/getting-started/data-fetching#useasyncdata"}
|
|
77
|
+
:read-more{to="/docs/4.x/getting-started/data-fetching#useasyncdata"}
|
|
78
78
|
|
|
79
79
|
## Params
|
|
80
80
|
|
|
81
81
|
- `key`: a unique key to ensure that data fetching can be properly de-duplicated across requests. If you do not provide a key, then a key that is unique to the file name and line number of the instance of `useAsyncData` will be generated for you.
|
|
82
82
|
- `handler`: an asynchronous function that must return a truthy value (for example, it should not be `undefined` or `null`) or the request may be duplicated on the client side.
|
|
83
83
|
::warning
|
|
84
|
-
The `handler` function should be **side-effect free** to ensure predictable behavior during SSR and CSR hydration. If you need to trigger side effects, use the [`callOnce`](/docs/api/utils/call-once) utility to do so.
|
|
84
|
+
The `handler` function should be **side-effect free** to ensure predictable behavior during SSR and CSR hydration. If you need to trigger side effects, use the [`callOnce`](/docs/4.x/api/utils/call-once) utility to do so.
|
|
85
85
|
::
|
|
86
86
|
- `options`:
|
|
87
87
|
- `server`: whether to fetch the data on the server (defaults to `true`)
|
|
@@ -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.
|
|
@@ -107,7 +107,7 @@ The `handler` function should be **side-effect free** to ensure predictable beha
|
|
|
107
107
|
Under the hood, `lazy: false` uses `<Suspense>` to block the loading of the route before the data has been fetched. Consider using `lazy: true` and implementing a loading state instead for a snappier user experience.
|
|
108
108
|
::
|
|
109
109
|
|
|
110
|
-
::read-more{to="/docs/api/composables/use-lazy-async-data"}
|
|
110
|
+
::read-more{to="/docs/4.x/api/composables/use-lazy-async-data"}
|
|
111
111
|
You can use `useLazyAsyncData` to have the same behavior as `lazy: true` with `useAsyncData`.
|
|
112
112
|
::
|
|
113
113
|
|
|
@@ -143,7 +143,7 @@ const { data: users2 } = useAsyncData('users', () => $fetch('/api/users'), { imm
|
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
::tip
|
|
146
|
-
Keyed state created using `useAsyncData` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/api/composables/use-nuxt-data).
|
|
146
|
+
Keyed state created using `useAsyncData` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/4.x/api/composables/use-nuxt-data).
|
|
147
147
|
::
|
|
148
148
|
|
|
149
149
|
## Return Values
|
|
@@ -163,17 +163,17 @@ Keyed state created using `useAsyncData` can be retrieved across your Nuxt appli
|
|
|
163
163
|
By default, Nuxt waits until a `refresh` is finished before it can be executed again.
|
|
164
164
|
|
|
165
165
|
::note
|
|
166
|
-
If you have not fetched data on the server (for example, with `server: false`), then the data _will not_ be fetched until hydration completes. This means even if you await [`useAsyncData`](/docs/api/composables/use-async-data) on the client side, `data` will remain `undefined` within `<script setup>`.
|
|
166
|
+
If you have not fetched data on the server (for example, with `server: false`), then the data _will not_ be fetched until hydration completes. This means even if you await [`useAsyncData`](/docs/4.x/api/composables/use-async-data) on the client side, `data` will remain `undefined` within `<script setup>`.
|
|
167
167
|
::
|
|
168
168
|
|
|
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'
|
|
@@ -213,4 +213,4 @@ interface AsyncDataExecuteOptions {
|
|
|
213
213
|
type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
-
:read-more{to="/docs/getting-started/data-fetching"}
|
|
216
|
+
:read-more{to="/docs/4.x/getting-started/data-fetching"}
|
|
@@ -17,7 +17,7 @@ const cookie = useCookie(name, options)
|
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
::note
|
|
20
|
-
`useCookie` only works in the [Nuxt context](/docs/guide/going-further/nuxt-app#the-nuxt-context).
|
|
20
|
+
`useCookie` only works in the [Nuxt context](/docs/4.x/guide/going-further/nuxt-app#the-nuxt-context).
|
|
21
21
|
::
|
|
22
22
|
|
|
23
23
|
::tip
|
|
@@ -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>
|
|
@@ -59,7 +59,7 @@ Most of the options will be directly passed to the [cookie](https://github.com/j
|
|
|
59
59
|
| `decode` | `(value: string) => T` | `decodeURIComponent` + [destr](https://github.com/unjs/destr). | Custom function to decode the cookie value. Since the value of a cookie has a limited character set (and must be a simple string), this function can be used to decode a previously encoded cookie value into a JavaScript string or other object. <br/> **Note:** If an error is thrown from this function, the original, non-decoded cookie value will be returned as the cookie's value. |
|
|
60
60
|
| `encode` | `(value: T) => string` | `JSON.stringify` + `encodeURIComponent` | Custom function to encode the cookie value. Since the value of a cookie has a limited character set (and must be a simple string), this function can be used to encode a value into a string suited for a cookie's value. |
|
|
61
61
|
| `default` | `() => T \| Ref<T>` | `undefined` | Function returning the default value if the cookie does not exist. The function can also return a `Ref`. |
|
|
62
|
-
| `watch` | `boolean \| 'shallow'` | `true` | Whether to watch for changes and update the cookie. `true` for deep watch, `'shallow'` for shallow watch, i.e. data changes for only top level properties, `false` to disable. <br/> **Note:** Refresh `useCookie` values manually when a cookie has changed with [`refreshCookie`](/docs/api/utils/refresh-cookie). |
|
|
62
|
+
| `watch` | `boolean \| 'shallow'` | `true` | Whether to watch for changes and update the cookie. `true` for deep watch, `'shallow'` for shallow watch, i.e. data changes for only top level properties, `false` to disable. <br/> **Note:** Refresh `useCookie` values manually when a cookie has changed with [`refreshCookie`](/docs/4.x/api/utils/refresh-cookie). |
|
|
63
63
|
| `readonly` | `boolean` | `false` | If `true`, disables writing to the cookie. |
|
|
64
64
|
| `maxAge` | `number` | `undefined` | Max age in seconds for the cookie, i.e. the value for the [`Max-Age` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.2). The given number will be converted to an integer by rounding down. By default, no maximum age is set. |
|
|
65
65
|
| `expires` | `Date` | `undefined` | Expiration date for the cookie. By default, no expiration is set. Most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application. <br/> **Note:** The [cookie storage model specification](https://tools.ietf.org/html/rfc6265#section-5.3) states that if both `expires` and `maxAge` is set, then `maxAge` takes precedence, but not all clients may obey this, so if both are set, they should point to the same date and time! <br/>If neither of `expires` and `maxAge` is set, the cookie will be session-only and removed when the user closes their browser. |
|
|
@@ -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
|
|
|
@@ -172,4 +180,4 @@ export default defineEventHandler(event => {
|
|
|
172
180
|
})
|
|
173
181
|
```
|
|
174
182
|
|
|
175
|
-
:link-example{to="/docs/examples/advanced/use-cookie"}
|
|
183
|
+
:link-example{to="/docs/4.x/examples/advanced/use-cookie"}
|
|
@@ -42,7 +42,7 @@ Returns a `Ref` containing the current Nuxt error (or `undefined` if there is no
|
|
|
42
42
|
|
|
43
43
|
## Example
|
|
44
44
|
|
|
45
|
-
```
|
|
45
|
+
```vue
|
|
46
46
|
<script setup lang="ts">
|
|
47
47
|
const error = useError()
|
|
48
48
|
|
|
@@ -52,4 +52,4 @@ if (error.value) {
|
|
|
52
52
|
</script>
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
:read-more{to="/docs/getting-started/error-handling"}
|
|
55
|
+
:read-more{to="/docs/4.x/getting-started/error-handling"}
|
|
@@ -8,7 +8,7 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
This composable provides a convenient wrapper around [`useAsyncData`](/docs/api/composables/use-async-data) and [`$fetch`](/docs/api/utils/dollarfetch).
|
|
11
|
+
This composable provides a convenient wrapper around [`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`$fetch`](/docs/4.x/api/utils/dollarfetch).
|
|
12
12
|
It automatically generates a key based on URL and fetch options, provides type hints for request url based on server routes, and infers API response type.
|
|
13
13
|
|
|
14
14
|
::note
|
|
@@ -20,13 +20,13 @@ 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
|
```
|
|
27
27
|
|
|
28
28
|
::warning
|
|
29
|
-
If you're using a custom useFetch wrapper, do not await it in the composable, as that can cause unexpected behavior. Please follow [this recipe](/docs/guide/recipes/custom-usefetch#custom-
|
|
29
|
+
If you're using a custom useFetch wrapper, do not await it in the composable, as that can cause unexpected behavior. Please follow [this recipe](/docs/4.x/guide/recipes/custom-usefetch#custom-usefetchuseasyncdata) for more information on how to make a custom async data fetcher.
|
|
30
30
|
::
|
|
31
31
|
|
|
32
32
|
::note
|
|
@@ -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
|
|
|
@@ -83,7 +83,7 @@ const { data: post } = await useFetch(() => `/api/posts/${id.value}`)
|
|
|
83
83
|
When using `useFetch` with the same URL and options in multiple components, they will share the same `data`, `error` and `status` refs. This ensures consistency across components.
|
|
84
84
|
|
|
85
85
|
::tip
|
|
86
|
-
Keyed state created using `useFetch` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/api/composables/use-nuxt-data).
|
|
86
|
+
Keyed state created using `useFetch` can be retrieved across your Nuxt application using [`useNuxtData`](/docs/4.x/api/composables/use-nuxt-data).
|
|
87
87
|
::
|
|
88
88
|
|
|
89
89
|
::warning
|
|
@@ -96,24 +96,49 @@ If you encounter the `data` variable destructured from a `useFetch` returns a st
|
|
|
96
96
|
|
|
97
97
|
:video-accordion{title="Watch the video from Alexander Lichter to avoid using useFetch the wrong way" videoId="njsGVmcWviY"}
|
|
98
98
|
|
|
99
|
-
:read-more{to="/docs/getting-started/data-fetching"}
|
|
99
|
+
:read-more{to="/docs/4.x/getting-started/data-fetching"}
|
|
100
|
+
|
|
101
|
+
### Reactive Fetch Options
|
|
102
|
+
|
|
103
|
+
Fetch options can be provided as reactive, supporting `computed`, `ref` and [computed getters](https://vuejs.org/guide/essentials/computed.html). When a reactive fetch option is updated it will trigger a refetch using the updated resolved reactive value.
|
|
104
|
+
|
|
105
|
+
```ts
|
|
106
|
+
const searchQuery = ref('initial')
|
|
107
|
+
const { data } = await useFetch('/api/search', {
|
|
108
|
+
query: { q: searchQuery },
|
|
109
|
+
})
|
|
110
|
+
// triggers a refetch: /api/search?q=new%20search
|
|
111
|
+
searchQuery.value = 'new search'
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If needed, you can opt out of this behavior using `watch: false`:
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
const searchQuery = ref('initial')
|
|
118
|
+
const { data } = await useFetch('/api/search', {
|
|
119
|
+
query: { q: searchQuery },
|
|
120
|
+
watch: false,
|
|
121
|
+
})
|
|
122
|
+
// does not trigger a refetch
|
|
123
|
+
searchQuery.value = 'new search'
|
|
124
|
+
```
|
|
100
125
|
|
|
101
126
|
## Type
|
|
102
127
|
|
|
103
128
|
```ts [Signature]
|
|
104
|
-
function useFetch<DataT, ErrorT>(
|
|
129
|
+
export function useFetch<DataT, ErrorT> (
|
|
105
130
|
url: string | Request | Ref<string | Request> | (() => string | Request),
|
|
106
131
|
options?: UseFetchOptions<DataT>
|
|
107
132
|
): Promise<AsyncData<DataT, ErrorT>>
|
|
108
133
|
|
|
109
134
|
type UseFetchOptions<DataT> = {
|
|
110
135
|
key?: MaybeRefOrGetter<string>
|
|
111
|
-
method?: string
|
|
112
|
-
query?: SearchParams
|
|
113
|
-
params?: SearchParams
|
|
114
|
-
body?: RequestInit['body'] | Record<string, any
|
|
115
|
-
headers?: Record<string, string> | [key: string, value: string][] | Headers
|
|
116
|
-
baseURL?: string
|
|
136
|
+
method?: MaybeRefOrGetter<string>
|
|
137
|
+
query?: MaybeRefOrGetter<SearchParams>
|
|
138
|
+
params?: MaybeRefOrGetter<SearchParams>
|
|
139
|
+
body?: MaybeRefOrGetter<RequestInit['body'] | Record<string, any>>
|
|
140
|
+
headers?: MaybeRefOrGetter<Record<string, string> | [key: string, value: string][] | Headers>
|
|
141
|
+
baseURL?: MaybeRefOrGetter<string>
|
|
117
142
|
server?: boolean
|
|
118
143
|
lazy?: boolean
|
|
119
144
|
immediate?: boolean
|
|
@@ -125,6 +150,7 @@ type UseFetchOptions<DataT> = {
|
|
|
125
150
|
pick?: string[]
|
|
126
151
|
$fetch?: typeof globalThis.$fetch
|
|
127
152
|
watch?: MultiWatchSources | false
|
|
153
|
+
timeout?: MaybeRefOrGetter<number>
|
|
128
154
|
}
|
|
129
155
|
|
|
130
156
|
type AsyncDataRequestContext = {
|
|
@@ -152,18 +178,18 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
|
|
|
152
178
|
|
|
153
179
|
- `URL` (`string | Request | Ref<string | Request> | () => string | Request`): The URL or request to fetch. Can be a string, a Request object, a Vue ref, or a function returning a string/Request. Supports reactivity for dynamic endpoints.
|
|
154
180
|
|
|
155
|
-
- `options` (object): Configuration for the fetch request. Extends [unjs/ofetch](https://github.com/unjs/ofetch) options and [`AsyncDataOptions`](/docs/api/composables/use-async-data#params). All options can be a static value, a `ref`, or a computed value.
|
|
181
|
+
- `options` (object): Configuration for the fetch request. Extends [unjs/ofetch](https://github.com/unjs/ofetch) options and [`AsyncDataOptions`](/docs/4.x/api/composables/use-async-data#params). All options can be a static value, a `ref`, or a computed value.
|
|
156
182
|
|
|
157
183
|
| Option | Type | Default | Description |
|
|
158
184
|
| ---| --- | --- | --- |
|
|
159
185
|
| `key` | `MaybeRefOrGetter<string>` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
|
|
160
|
-
| `method` | `string
|
|
161
|
-
| `query` | `
|
|
162
|
-
| `params` | `
|
|
163
|
-
| `body` | `RequestInit['body'] \| Record<string, any
|
|
164
|
-
| `headers` | `Record<string, string> \| [key, value][] \| Headers
|
|
165
|
-
| `baseURL` | `string
|
|
166
|
-
| `timeout` | `number
|
|
186
|
+
| `method` | `MaybeRefOrGetter<string>` | `'GET'` | HTTP request method. |
|
|
187
|
+
| `query` | `MaybeRefOrGetter<SearchParams>` | - | Query/search params to append to the URL. Alias: `params`. |
|
|
188
|
+
| `params` | `MaybeRefOrGetter<SearchParams>` | - | Alias for `query`. |
|
|
189
|
+
| `body` | `MaybeRefOrGetter<RequestInit['body'] \| Record<string, any>>` | - | Request body. Objects are automatically stringified. |
|
|
190
|
+
| `headers` | `MaybeRefOrGetter<Record<string, string> \| [key, value][] \| Headers>` | - | Request headers. |
|
|
191
|
+
| `baseURL` | `MaybeRefOrGetter<string>` | - | Base URL for the request. |
|
|
192
|
+
| `timeout` | `MaybeRefOrGetter<number>` | - | Timeout in milliseconds to abort the request. |
|
|
167
193
|
| `cache` | `boolean \| string` | - | Cache control. Boolean disables cache, or use Fetch API values: `default`, `no-store`, etc. |
|
|
168
194
|
| `server` | `boolean` | `true` | Whether to fetch on the server. |
|
|
169
195
|
| `lazy` | `boolean` | `false` | If true, resolves after route loads (does not block navigation). |
|
|
@@ -175,7 +201,7 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
|
|
|
175
201
|
| `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
|
|
176
202
|
| `deep` | `boolean` | `false` | Return data in a deep ref object. |
|
|
177
203
|
| `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
|
|
178
|
-
| `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. |
|
|
204
|
+
| `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. See [Custom useFetch in Nuxt](/docs/4.x/guide/recipes/custom-usefetch) |
|
|
179
205
|
|
|
180
206
|
::note
|
|
181
207
|
All fetch options can be given a `computed` or `ref` value. These will be watched and new requests made automatically with any new values if they are updated.
|
|
@@ -184,9 +210,9 @@ All fetch options can be given a `computed` or `ref` value. These will be watche
|
|
|
184
210
|
**getCachedData default:**
|
|
185
211
|
|
|
186
212
|
```ts
|
|
187
|
-
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
188
|
-
|
|
189
|
-
|
|
213
|
+
const getDefaultCachedData = (key, nuxtApp, ctx) => nuxtApp.isHydrating
|
|
214
|
+
? nuxtApp.payload.data[key]
|
|
215
|
+
: nuxtApp.static.data[key]
|
|
190
216
|
```
|
|
191
217
|
This only caches data when `experimental.payloadExtraction` in `nuxt.config` is enabled.
|
|
192
218
|
|
|
@@ -214,6 +240,6 @@ If you have not fetched data on the server (for example, with `server: false`),
|
|
|
214
240
|
|
|
215
241
|
### Examples
|
|
216
242
|
|
|
217
|
-
:link-example{to="/docs/examples/advanced/use-custom-fetch-composable"}
|
|
243
|
+
:link-example{to="/docs/4.x/examples/advanced/use-custom-fetch-composable"}
|
|
218
244
|
|
|
219
|
-
:link-example{to="/docs/examples/features/data-fetching"}
|
|
245
|
+
:link-example{to="/docs/4.x/examples/features/data-fetching"}
|
|
@@ -8,20 +8,20 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
The `useHeadSafe` composable is a wrapper around the [`useHead`](/docs/api/composables/use-head) composable that restricts the input to only allow safe values.
|
|
11
|
+
The `useHeadSafe` composable is a wrapper around the [`useHead`](/docs/4.x/api/composables/use-head) composable that restricts the input to only allow safe values.
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
You can pass all the same values as [`useHead`](/docs/api/composables/use-head)
|
|
15
|
+
You can pass all the same values as [`useHead`](/docs/4.x/api/composables/use-head)
|
|
16
16
|
|
|
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:
|
|
@@ -8,17 +8,17 @@ links:
|
|
|
8
8
|
size: xs
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
-
The [`useHead`](/docs/api/composables/use-head) composable function allows you to manage your head tags in a programmatic and reactive way, powered by [Unhead](https://unhead.unjs.io). If the data comes from a user or other untrusted source, we recommend you check out [`useHeadSafe`](/docs/api/composables/use-head-safe).
|
|
11
|
+
The [`useHead`](/docs/4.x/api/composables/use-head) composable function allows you to manage your head tags in a programmatic and reactive way, powered by [Unhead](https://unhead.unjs.io). If the data comes from a user or other untrusted source, we recommend you check out [`useHeadSafe`](/docs/4.x/api/composables/use-head-safe).
|
|
12
12
|
|
|
13
|
-
:read-more{to="/docs/getting-started/seo-meta"}
|
|
13
|
+
:read-more{to="/docs/4.x/getting-started/seo-meta"}
|
|
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
|
-
Below are the non-reactive types for [`useHead`](/docs/api/composables/use-head) .
|
|
21
|
+
Below are the non-reactive types for [`useHead`](/docs/4.x/api/composables/use-head) .
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
24
|
interface MetaObject {
|
|
@@ -13,7 +13,7 @@ This is an advanced composable, primarily designed for use within plugins, mostl
|
|
|
13
13
|
::
|
|
14
14
|
|
|
15
15
|
::note
|
|
16
|
-
`useHydration` is designed to **ensure state synchronization and restoration during SSR**. If you need to create a globally reactive state that is SSR-friendly in Nuxt, [`useState`](/docs/api/composables/use-state) is the recommended choice.
|
|
16
|
+
`useHydration` is designed to **ensure state synchronization and restoration during SSR**. If you need to create a globally reactive state that is SSR-friendly in Nuxt, [`useState`](/docs/4.x/api/composables/use-state) is the recommended choice.
|
|
17
17
|
::
|
|
18
18
|
|
|
19
19
|
`useHydration` is a built-in composable that provides a way to set data on the server side every time a new HTTP request is made and receive that data on the client side. This way `useHydration` allows you to take full control of the hydration cycle.
|
|
@@ -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
|
|
@@ -10,13 +10,13 @@ links:
|
|
|
10
10
|
|
|
11
11
|
## Description
|
|
12
12
|
|
|
13
|
-
By default, [`useAsyncData`](/docs/api/composables/use-async-data) blocks navigation until its async handler is resolved. `useLazyAsyncData` provides a wrapper around [`useAsyncData`](/docs/api/composables/use-async-data) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
|
|
13
|
+
By default, [`useAsyncData`](/docs/4.x/api/composables/use-async-data) blocks navigation until its async handler is resolved. `useLazyAsyncData` provides a wrapper around [`useAsyncData`](/docs/4.x/api/composables/use-async-data) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
|
|
14
14
|
|
|
15
15
|
::note
|
|
16
|
-
`useLazyAsyncData` has the same signature as [`useAsyncData`](/docs/api/composables/use-async-data).
|
|
16
|
+
`useLazyAsyncData` has the same signature as [`useAsyncData`](/docs/4.x/api/composables/use-async-data).
|
|
17
17
|
::
|
|
18
18
|
|
|
19
|
-
:read-more{to="/docs/api/composables/use-async-data"}
|
|
19
|
+
:read-more{to="/docs/4.x/api/composables/use-async-data"}
|
|
20
20
|
|
|
21
21
|
## Example
|
|
22
22
|
|
|
@@ -44,4 +44,4 @@ watch(count, (newCount) => {
|
|
|
44
44
|
`useLazyAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyAsyncData`.
|
|
45
45
|
::
|
|
46
46
|
|
|
47
|
-
:read-more{to="/docs/getting-started/data-fetching"}
|
|
47
|
+
:read-more{to="/docs/4.x/getting-started/data-fetching"}
|