@nuxt/docs-nightly 4.5.1-29752449.30d24817 → 4.5.2-2610052030-052d82e
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 +8 -8
- package/1.getting-started/02.installation.md +2 -4
- package/1.getting-started/03.configuration.md +16 -16
- package/1.getting-started/04.views.md +8 -8
- package/1.getting-started/05.assets.md +10 -10
- package/1.getting-started/06.styling.md +10 -10
- package/1.getting-started/07.routing.md +15 -15
- package/1.getting-started/08.seo-meta.md +15 -15
- package/1.getting-started/09.transitions.md +10 -10
- package/1.getting-started/10.data-fetching.md +61 -47
- package/1.getting-started/11.state-management.md +11 -11
- package/1.getting-started/12.error-handling.md +20 -18
- package/1.getting-started/13.server.md +7 -7
- package/1.getting-started/14.layers.md +6 -6
- package/1.getting-started/15.prerendering.md +22 -28
- package/1.getting-started/16.deployment.md +22 -6
- package/1.getting-started/17.testing.md +200 -21
- package/1.getting-started/18.upgrade.md +78 -278
- package/2.directory-structure/0.nuxt.md +2 -2
- package/2.directory-structure/0.output.md +3 -3
- package/2.directory-structure/1.app/1.assets.md +3 -3
- package/2.directory-structure/1.app/1.components.md +26 -109
- package/2.directory-structure/1.app/1.composables.md +5 -5
- package/2.directory-structure/1.app/1.layouts.md +10 -10
- package/2.directory-structure/1.app/1.middleware.md +14 -10
- package/2.directory-structure/1.app/1.pages.md +25 -20
- package/2.directory-structure/1.app/1.plugins.md +7 -7
- package/2.directory-structure/1.app/1.utils.md +9 -5
- package/2.directory-structure/1.app/3.app-config.md +7 -7
- package/2.directory-structure/1.app/3.app.md +6 -6
- package/2.directory-structure/1.app/3.error.md +1 -1
- package/2.directory-structure/1.content.md +1 -1
- package/2.directory-structure/1.layers.md +13 -13
- package/2.directory-structure/1.modules.md +3 -3
- package/2.directory-structure/1.node_modules.md +1 -1
- package/2.directory-structure/1.server.md +33 -14
- package/2.directory-structure/1.shared.md +7 -5
- package/2.directory-structure/1.test.md +25 -0
- package/2.directory-structure/2.env.md +7 -7
- package/2.directory-structure/2.nuxtignore.md +3 -3
- package/2.directory-structure/2.nuxtrc.md +3 -3
- package/2.directory-structure/3.nuxt-config.md +2 -2
- package/2.directory-structure/3.tsconfig.md +21 -11
- package/2.directory-structure/index.md +29 -25
- package/3.guide/0.index.md +6 -6
- package/3.guide/1.concepts/1.rendering.md +76 -12
- package/3.guide/1.concepts/10.vuejs-development.md +73 -8
- package/3.guide/1.concepts/2.nuxt-lifecycle.md +18 -18
- package/3.guide/1.concepts/3.auto-imports.md +11 -11
- package/3.guide/1.concepts/4.server-engine.md +6 -6
- package/3.guide/1.concepts/5.modules.md +4 -4
- package/3.guide/1.concepts/6.server-components.md +198 -0
- package/3.guide/1.concepts/7.esm.md +5 -5
- package/3.guide/1.concepts/8.typescript.md +9 -9
- package/3.guide/2.best-practices/accessibility.md +155 -0
- package/3.guide/2.best-practices/hydration.md +5 -5
- package/3.guide/2.best-practices/performance.md +13 -9
- package/3.guide/3.ai/1.mcp.md +104 -19
- package/3.guide/4.modules/2.module-anatomy.md +5 -5
- package/3.guide/4.modules/3.recipes-basics.md +8 -8
- package/3.guide/4.modules/4.module-dependencies.md +1 -1
- package/3.guide/4.modules/5.recipes-advanced.md +6 -8
- package/3.guide/4.modules/6.testing.md +2 -2
- package/3.guide/4.modules/7.best-practices.md +2 -2
- package/3.guide/4.modules/9.server-compatibility.md +215 -0
- package/3.guide/4.modules/index.md +9 -9
- package/3.guide/5.recipes/1.custom-routing.md +15 -11
- package/3.guide/5.recipes/2.vite-plugin.md +3 -3
- package/3.guide/5.recipes/3.custom-usefetch.md +5 -5
- package/3.guide/5.recipes/4.sessions-and-authentication.md +2 -2
- package/3.guide/5.recipes/5.mostly-static-sites.md +127 -0
- package/3.guide/6.going-further/1.events.md +1 -1
- package/3.guide/6.going-further/1.experimental-features.md +254 -22
- package/3.guide/6.going-further/1.features.md +42 -6
- package/3.guide/6.going-further/1.internals.md +10 -10
- package/3.guide/6.going-further/10.runtime-config.md +28 -6
- package/3.guide/6.going-further/11.nightly-release-channel.md +1 -1
- package/3.guide/6.going-further/2.hooks.md +6 -6
- package/3.guide/6.going-further/4.kit.md +4 -4
- package/3.guide/6.going-further/5.server-imports.md +221 -0
- package/3.guide/6.going-further/6.nuxt-app.md +7 -7
- package/3.guide/6.going-further/7.layers.md +13 -13
- package/3.guide/6.going-further/8.builders.md +38 -14
- package/4.api/1.components/1.nuxt-client-fallback.md +1 -1
- package/4.api/1.components/10.nuxt-picture.md +1 -1
- package/4.api/1.components/11.teleports.md +1 -1
- package/4.api/1.components/12.nuxt-route-announcer.md +5 -3
- package/4.api/1.components/14.nuxt-announcer.md +3 -3
- package/4.api/1.components/2.nuxt-page.md +5 -5
- package/4.api/1.components/3.nuxt-layout.md +8 -8
- package/4.api/1.components/4.nuxt-link.md +6 -4
- package/4.api/1.components/5.nuxt-loading-indicator.md +3 -3
- package/4.api/1.components/6.nuxt-error-boundary.md +1 -1
- package/4.api/1.components/8.nuxt-island.md +5 -5
- package/4.api/2.composables/create-use-async-data.md +51 -8
- package/4.api/2.composables/create-use-fetch.md +126 -9
- package/4.api/2.composables/use-announcer.md +3 -3
- package/4.api/2.composables/use-app-config.md +1 -1
- package/4.api/2.composables/use-async-data.md +19 -11
- package/4.api/2.composables/use-cookie.md +22 -6
- package/4.api/2.composables/use-error.md +1 -1
- package/4.api/2.composables/use-fetch.md +14 -10
- package/4.api/2.composables/use-head-safe.md +2 -2
- package/4.api/2.composables/use-head.md +2 -2
- package/4.api/2.composables/use-hydration.md +1 -1
- package/4.api/2.composables/use-layout.md +1 -1
- package/4.api/2.composables/use-lazy-async-data.md +8 -8
- package/4.api/2.composables/use-lazy-fetch.md +11 -11
- package/4.api/2.composables/use-loading-indicator.md +2 -2
- package/4.api/2.composables/use-nuxt-app.md +13 -13
- package/4.api/2.composables/use-nuxt-data.md +1 -1
- package/4.api/2.composables/use-preview-mode.md +3 -3
- package/4.api/2.composables/use-request-event.md +29 -3
- package/4.api/2.composables/use-request-fetch.md +2 -2
- package/4.api/2.composables/use-request-header.md +1 -1
- package/4.api/2.composables/use-request-headers.md +1 -1
- package/4.api/2.composables/use-request-url.md +1 -1
- package/4.api/2.composables/use-response-header.md +2 -2
- package/4.api/2.composables/use-route-announcer.md +4 -2
- package/4.api/2.composables/use-route.md +2 -2
- package/4.api/2.composables/use-router.md +5 -5
- package/4.api/2.composables/use-runtime-config.md +5 -5
- package/4.api/2.composables/use-runtime-hook.md +1 -1
- package/4.api/2.composables/use-seo-meta.md +3 -3
- package/4.api/2.composables/use-server-seo-meta.md +5 -5
- package/4.api/2.composables/use-state.md +4 -4
- package/4.api/3.utils/$fetch.md +5 -5
- package/4.api/3.utils/abort-navigation.md +1 -1
- package/4.api/3.utils/add-route-middleware.md +2 -2
- package/4.api/3.utils/call-once.md +3 -3
- package/4.api/3.utils/clear-error.md +2 -2
- package/4.api/3.utils/clear-nuxt-data.md +1 -1
- package/4.api/3.utils/clear-nuxt-state.md +2 -2
- package/4.api/3.utils/create-error.md +19 -1
- package/4.api/3.utils/define-nuxt-plugin.md +2 -2
- package/4.api/3.utils/define-nuxt-route-middleware.md +3 -3
- package/4.api/3.utils/define-page-meta.md +12 -12
- package/4.api/3.utils/define-route-rules.md +4 -4
- package/4.api/3.utils/define-use-async-data-addon.md +57 -0
- package/4.api/3.utils/define-use-fetch-addon.md +168 -0
- package/4.api/3.utils/navigate-to.md +6 -2
- package/4.api/3.utils/prefetch-components.md +1 -1
- package/4.api/3.utils/preload-route-components.md +2 -2
- package/4.api/3.utils/prerender-routes.md +3 -3
- package/4.api/3.utils/refresh-cookie.md +1 -1
- package/4.api/3.utils/refresh-nuxt-data.md +3 -3
- package/4.api/3.utils/reload-nuxt-app.md +1 -1
- package/4.api/3.utils/set-page-layout.md +1 -1
- package/4.api/3.utils/set-response-status.md +2 -2
- package/4.api/3.utils/show-error.md +3 -3
- package/4.api/3.utils/update-app-config.md +2 -2
- package/4.api/4.commands/README.md +9 -0
- package/4.api/5.kit/1.modules.md +3 -3
- package/4.api/5.kit/10.runtime-config.md +1 -1
- package/4.api/5.kit/10.templates.md +42 -0
- package/4.api/5.kit/12.nitro.md +59 -18
- package/4.api/5.kit/14.logging.md +56 -2
- package/4.api/5.kit/15.builder.md +1 -1
- package/4.api/5.kit/18.dependencies.md +90 -0
- package/4.api/5.kit/2.programmatic.md +78 -1
- package/4.api/5.kit/3.compatibility.md +2 -2
- package/4.api/5.kit/4.autoimports.md +13 -13
- package/4.api/5.kit/5.components.md +3 -3
- package/4.api/5.kit/6.context.md +2 -2
- package/4.api/5.kit/7.pages.md +35 -4
- package/4.api/5.kit/8.layout.md +1 -1
- package/4.api/6.advanced/1.hooks.md +6 -3
- package/4.api/6.nuxt-config.md +44 -21
- package/4.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 +14 -12
- package/5.community/5.framework-contribution.md +4 -4
- package/5.community/6.roadmap.md +6 -6
- package/6.bridge/1.overview.md +12 -12
- package/6.bridge/2.typescript.md +1 -1
- package/6.bridge/3.bridge-composition-api.md +6 -6
- package/6.bridge/4.plugins-and-middleware.md +4 -4
- package/6.bridge/5.nuxt3-compatible-api.md +9 -9
- package/6.bridge/6.meta.md +5 -5
- package/6.bridge/7.runtime-config.md +1 -1
- package/6.bridge/8.nitro.md +1 -1
- package/6.bridge/9.vite.md +1 -1
- 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 +6 -6
- package/7.migration/20.module-authors.md +7 -7
- package/7.migration/3.auto-imports.md +3 -3
- package/7.migration/4.meta.md +4 -4
- package/7.migration/5.plugins-and-middleware.md +3 -3
- package/7.migration/6.pages-and-layouts.md +13 -13
- package/7.migration/7.component-options.md +15 -15
- package/7.migration/8.runtime-config.md +4 -4
- package/README.md +1 -1
- package/errors/e8007.md +28 -0
- package/package.json +2 -2
- package/4.api/4.commands/.navigation.yml +0 -3
- package/4.api/4.commands/add.md +0 -112
- package/4.api/4.commands/analyze.md +0 -42
- package/4.api/4.commands/build-module.md +0 -42
- package/4.api/4.commands/build.md +0 -48
- package/4.api/4.commands/cleanup.md +0 -38
- package/4.api/4.commands/dev.md +0 -61
- package/4.api/4.commands/devtools.md +0 -38
- package/4.api/4.commands/generate.md +0 -43
- package/4.api/4.commands/info.md +0 -33
- package/4.api/4.commands/init.md +0 -50
- package/4.api/4.commands/module.md +0 -84
- package/4.api/4.commands/prepare.md +0 -41
- package/4.api/4.commands/preview.md +0 -44
- package/4.api/4.commands/test.md +0 -40
- package/4.api/4.commands/typecheck.md +0 -44
- package/4.api/4.commands/upgrade.md +0 -37
|
@@ -14,7 +14,7 @@ Because Nuxt uses Vue's `<Transition>` component, a page or layout you want to a
|
|
|
14
14
|
|
|
15
15
|
## Page Transitions
|
|
16
16
|
|
|
17
|
-
You can enable page transitions to apply an automatic transition for all your [pages](/docs/
|
|
17
|
+
You can enable page transitions to apply an automatic transition for all your [pages](/docs/directory-structure/app/pages).
|
|
18
18
|
|
|
19
19
|
```ts twoslash [nuxt.config.ts]
|
|
20
20
|
export default defineNuxtConfig({
|
|
@@ -25,10 +25,10 @@ export default defineNuxtConfig({
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
::note
|
|
28
|
-
If you are changing layouts as well as
|
|
28
|
+
If you are changing layouts as well as pages, the page transition you set here will not run. Instead, you should set a [layout transition](/docs/getting-started/transitions#layout-transitions).
|
|
29
29
|
::
|
|
30
30
|
|
|
31
|
-
To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/
|
|
31
|
+
To start adding transition between your pages, add the following CSS to your [`app.vue`](/docs/directory-structure/app/app):
|
|
32
32
|
|
|
33
33
|
::code-group
|
|
34
34
|
|
|
@@ -76,7 +76,7 @@ This produces the following result when navigating between pages:
|
|
|
76
76
|
<source src="https://res.cloudinary.com/nuxt/video/upload/v1665061349/nuxt3/nuxt3-page-transitions_umwvmh.mp4" type="video/mp4">
|
|
77
77
|
</video>
|
|
78
78
|
|
|
79
|
-
To set a different transition for a page, set the `pageTransition` key in [`definePageMeta`](/docs/
|
|
79
|
+
To set a different transition for a page, set the `pageTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page:
|
|
80
80
|
|
|
81
81
|
::code-group
|
|
82
82
|
|
|
@@ -119,7 +119,7 @@ Moving to the about page will add the 3d rotation effect:
|
|
|
119
119
|
|
|
120
120
|
## Layout Transitions
|
|
121
121
|
|
|
122
|
-
You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/
|
|
122
|
+
You can enable layout transitions to apply an automatic transition for all your [layouts](/docs/directory-structure/app/layouts).
|
|
123
123
|
|
|
124
124
|
```ts twoslash [nuxt.config.ts]
|
|
125
125
|
export default defineNuxtConfig({
|
|
@@ -129,7 +129,7 @@ export default defineNuxtConfig({
|
|
|
129
129
|
})
|
|
130
130
|
```
|
|
131
131
|
|
|
132
|
-
To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/
|
|
132
|
+
To start adding transition between your pages and layouts, add the following CSS to your [`app.vue`](/docs/directory-structure/app/app):
|
|
133
133
|
|
|
134
134
|
::code-group
|
|
135
135
|
|
|
@@ -319,7 +319,7 @@ Learn more about additional [JavaScript hooks](https://vuejs.org/guide/built-ins
|
|
|
319
319
|
|
|
320
320
|
## Dynamic Transitions
|
|
321
321
|
|
|
322
|
-
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/
|
|
322
|
+
To apply dynamic transitions using conditional logic, you can leverage inline [middleware](/docs/directory-structure/app/middleware) to assign a different transition name to `to.meta.pageTransition`.
|
|
323
323
|
|
|
324
324
|
::code-group
|
|
325
325
|
|
|
@@ -389,7 +389,7 @@ const next = computed(() => '/' + (id.value + 1))
|
|
|
389
389
|
|
|
390
390
|
::
|
|
391
391
|
|
|
392
|
-
The page now applies the `slide-left` transition when going to the next id and `slide-right` for the previous:
|
|
392
|
+
The page now applies the `slide-left` transition when going to the next id and `slide-right` for the previous one:
|
|
393
393
|
|
|
394
394
|
<video controls class="rounded" poster="https://res.cloudinary.com/nuxt/video/upload/v1665069410/nuxt3/nuxt-dynamic-page-transitions.jpg">
|
|
395
395
|
<source src="https://res.cloudinary.com/nuxt/video/upload/v1665069410/nuxt3/nuxt-dynamic-page-transitions.mp4" type="video/mp4">
|
|
@@ -438,7 +438,7 @@ The possible values are: `false`, `true`, or `'always'`.
|
|
|
438
438
|
|
|
439
439
|
If set to true, Nuxt will not apply transitions if the user's browser matches `prefers-reduced-motion: reduce` (recommended). If set to `always`, Nuxt will always apply the transition and it is up to you to respect the user's preference.
|
|
440
440
|
|
|
441
|
-
By default, view transitions are enabled for all [pages](/docs/
|
|
441
|
+
By default, view transitions are enabled for all [pages](/docs/directory-structure/app/pages), but you can set a different global default.
|
|
442
442
|
|
|
443
443
|
```ts twoslash [nuxt.config.ts]
|
|
444
444
|
export default defineNuxtConfig({
|
|
@@ -449,7 +449,7 @@ export default defineNuxtConfig({
|
|
|
449
449
|
})
|
|
450
450
|
```
|
|
451
451
|
|
|
452
|
-
It is possible to override the default `viewTransition` value for a page by setting the `viewTransition` key in [`definePageMeta`](/docs/
|
|
452
|
+
It is possible to override the default `viewTransition` value for a page by setting the `viewTransition` key in [`definePageMeta`](/docs/api/utils/define-page-meta) of the page:
|
|
453
453
|
|
|
454
454
|
```vue twoslash [pages/about.vue]
|
|
455
455
|
<script setup lang="ts">
|
|
@@ -4,23 +4,23 @@ description: Nuxt provides composables to handle data fetching within your appli
|
|
|
4
4
|
navigation.icon: i-lucide-cable
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Nuxt comes with two composables and a built-in library to perform data-fetching in browser or server environments: `useFetch`, [`useAsyncData`](/docs/
|
|
7
|
+
Nuxt comes with two composables and a built-in library to perform data-fetching in browser or server environments: `useFetch`, [`useAsyncData`](/docs/api/composables/use-async-data) and `$fetch`.
|
|
8
8
|
|
|
9
9
|
In a nutshell:
|
|
10
10
|
|
|
11
|
-
- [`$fetch`](/docs/
|
|
12
|
-
- [`useFetch`](/docs/
|
|
13
|
-
- [`useAsyncData`](/docs/
|
|
11
|
+
- [`$fetch`](/docs/api/utils/dollarfetch) is the simplest way to make a network request.
|
|
12
|
+
- [`useFetch`](/docs/api/composables/use-fetch) is a wrapper around `$fetch` that fetches data only once in [universal rendering](/docs/guide/concepts/rendering#universal-rendering).
|
|
13
|
+
- [`useAsyncData`](/docs/api/composables/use-async-data) is similar to `useFetch` but offers more fine-grained control.
|
|
14
14
|
|
|
15
15
|
Both `useFetch` and `useAsyncData` share a common set of options and patterns that we will detail in the last sections.
|
|
16
16
|
|
|
17
17
|
## The Need for `useFetch` and `useAsyncData`
|
|
18
18
|
|
|
19
|
-
Nuxt is a framework which can run isomorphic (or universal) code in both server and client environments. If the [`$fetch` function](/docs/
|
|
19
|
+
Nuxt is a framework which can run isomorphic (or universal) code in both server and client environments. If the [`$fetch` function](/docs/api/utils/dollarfetch) is used to perform data fetching in the setup function of a Vue component, this may cause data to be fetched twice, once on the server (to render the HTML) and once again on the client (when the HTML is hydrated). This can cause hydration issues, increase the time to interactivity and cause unpredictable behavior.
|
|
20
20
|
|
|
21
|
-
The [`useFetch`](/docs/
|
|
21
|
+
The [`useFetch`](/docs/api/composables/use-fetch) and [`useAsyncData`](/docs/api/composables/use-async-data) composables solve this problem by ensuring that if an API call is made on the server, the data is forwarded to the client in the payload.
|
|
22
22
|
|
|
23
|
-
The payload is a JavaScript object accessible through [`useNuxtApp().payload`](/docs/
|
|
23
|
+
The payload is a JavaScript object accessible through [`useNuxtApp().payload`](/docs/api/composables/use-nuxt-app#payload). It is used on the client to avoid refetching the same data when the code is executed in the browser [during hydration](/docs/guide/concepts/rendering#universal-rendering).
|
|
24
24
|
|
|
25
25
|
::tip
|
|
26
26
|
Use the [Nuxt DevTools](https://devtools.nuxt.com) to inspect this data in the **Payload tab**.
|
|
@@ -52,14 +52,14 @@ async function handleFormSubmit () {
|
|
|
52
52
|
</template>
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
-
In the example above, `useFetch` would make sure that the request would occur
|
|
55
|
+
In the example above, `useFetch` would make sure that the request would occur on the server and is properly forwarded to the browser. `$fetch` has no such mechanism and is a better option to use when the request is solely made from the browser.
|
|
56
56
|
|
|
57
57
|
### Suspense
|
|
58
58
|
|
|
59
59
|
Nuxt uses Vue's [`<Suspense>`](https://vuejs.org/guide/built-ins/suspense) component under the hood to prevent navigation before every async data is available to the view. The data fetching composables can help you leverage this feature and use what suits best on a per-call basis.
|
|
60
60
|
|
|
61
61
|
::note
|
|
62
|
-
You can add the [`<NuxtLoadingIndicator>`](/docs/
|
|
62
|
+
You can add the [`<NuxtLoadingIndicator>`](/docs/api/components/nuxt-loading-indicator) to add a progress bar between page navigations.
|
|
63
63
|
::
|
|
64
64
|
|
|
65
65
|
### A note on `await`
|
|
@@ -70,12 +70,12 @@ The `await` does **not** change the server-rendered HTML. During server renderin
|
|
|
70
70
|
|
|
71
71
|
What the `await` *does* change is what happens next in your own `<script setup>`, and how client-side navigation behaves:
|
|
72
72
|
|
|
73
|
-
- **With `await`**, execution pauses until the data is ready, so any code after the call can rely on `data` already being populated. On client-side navigation, this blocks navigation until the data resolves: the user stays on the current page (optionally with a [`<NuxtLoadingIndicator>`](/docs/
|
|
73
|
+
- **With `await`**, execution pauses until the data is ready, so any code after the call can rely on `data` already being populated. On client-side navigation, this blocks navigation until the data resolves: the user stays on the current page (optionally with a [`<NuxtLoadingIndicator>`](/docs/api/components/nuxt-loading-indicator)) and then lands on a fully populated page. This is the default behaviour.
|
|
74
74
|
- **Without `await`**, execution continues immediately while the request runs in the background, so `data` starts as its default value and fills in once the request resolves. On client-side navigation, this means navigation happens immediately and you are responsible for handling the loading and error states, typically via the returned `status` and `error` refs.
|
|
75
75
|
|
|
76
76
|
Neither approach is universally better; the right choice depends on the experience you want for that route.
|
|
77
77
|
|
|
78
|
-
Not awaiting has a similar user-visible effect to the [`lazy`](#lazy) option (navigation is not blocked and you handle loading state yourself), but the two are not identical: `lazy` is an explicit flag that defers the request until the component mounts, whereas simply not awaiting starts the request during setup. Prefer `lazy` (or [`useLazyFetch`](/docs/
|
|
78
|
+
Not awaiting has a similar user-visible effect to the [`lazy`](#lazy) option (navigation is not blocked and you handle loading state yourself), but the two are not identical: `lazy` is an explicit flag that defers the request until the component mounts, whereas simply not awaiting starts the request during setup. Prefer `lazy` (or [`useLazyFetch`](/docs/api/composables/use-lazy-fetch) / [`useLazyAsyncData`](/docs/api/composables/use-lazy-async-data)) when you want non-blocking behaviour, since it makes the intent explicit.
|
|
79
79
|
|
|
80
80
|
::warning
|
|
81
81
|
The `await` and `lazy` are independent, and on the client awaiting a `lazy` function won't have the effect you expect. If you `await` a `lazy` call (for example `await useLazyFetch(...)` or `await useFetch(..., { lazy: true })`), it still blocks server rendering as usual, but on **client-side navigation** the `await` resolves immediately without waiting for the request. `data` will still be at its default value right after the `await`, and you must handle the loading state via `status`. If you actually want the navigation to wait for the data, drop the `lazy` option rather than relying on `await`.
|
|
@@ -99,17 +99,31 @@ async function addTodo () {
|
|
|
99
99
|
```
|
|
100
100
|
|
|
101
101
|
::warning
|
|
102
|
-
Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](/docs/
|
|
103
|
-
It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](/docs/
|
|
102
|
+
Beware that using only `$fetch` will not provide [network calls de-duplication and navigation prevention](/docs/getting-started/data-fetching#the-need-for-usefetch-and-useasyncdata). :br
|
|
103
|
+
It is recommended to use `$fetch` for client-side interactions (event-based) or combined with [`useAsyncData`](/docs/getting-started/data-fetching#useasyncdata) when fetching the initial component data.
|
|
104
104
|
::
|
|
105
105
|
|
|
106
|
-
::read-more{to="/docs/
|
|
106
|
+
::read-more{to="/docs/api/utils/dollarfetch"}
|
|
107
107
|
Read more about `$fetch`.
|
|
108
108
|
::
|
|
109
109
|
|
|
110
|
+
### Typing a Value That Holds `$fetch`
|
|
111
|
+
|
|
112
|
+
To type a value that holds `$fetch` itself, such as a `$fetch` instance passed into a plugin or provided through `provide`/`inject`, use the `$Fetch` type (an alias of `TypedFetch`):
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import type { $Fetch } from '#app'
|
|
116
|
+
|
|
117
|
+
function createClient (fetcher: $Fetch) {
|
|
118
|
+
return {
|
|
119
|
+
todos: () => fetcher('/api/todos'),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
110
124
|
### Pass Client Headers to the API
|
|
111
125
|
|
|
112
|
-
When calling `useFetch` on the server, Nuxt will use [`useRequestFetch`](/docs/
|
|
126
|
+
When calling `useFetch` on the server, Nuxt will use [`useRequestFetch`](/docs/api/composables/use-request-fetch) to proxy client headers and cookies (with the exception of headers not meant to be forwarded, like `host`).
|
|
113
127
|
|
|
114
128
|
```vue
|
|
115
129
|
<script setup lang="ts">
|
|
@@ -122,7 +136,7 @@ const { data } = await useFetch('/api/echo')
|
|
|
122
136
|
export default defineEventHandler(event => parseCookies(event))
|
|
123
137
|
```
|
|
124
138
|
|
|
125
|
-
Alternatively, the example below shows how to use [`useRequestHeaders`](/docs/
|
|
139
|
+
Alternatively, the example below shows how to use [`useRequestHeaders`](/docs/api/composables/use-request-headers) to access and send cookies to the API from a server-side request (originating on the client). Using an isomorphic `$fetch` call, we ensure that the API endpoint has access to the same `cookie` header originally sent by the user's browser. This is only necessary if you aren't using `useFetch`.
|
|
126
140
|
|
|
127
141
|
```vue
|
|
128
142
|
<script setup lang="ts">
|
|
@@ -135,7 +149,7 @@ async function getCurrentUser () {
|
|
|
135
149
|
```
|
|
136
150
|
|
|
137
151
|
::tip
|
|
138
|
-
You can also use [`useRequestFetch`](/docs/
|
|
152
|
+
You can also use [`useRequestFetch`](/docs/api/composables/use-request-fetch) to proxy headers to the call automatically.
|
|
139
153
|
::
|
|
140
154
|
|
|
141
155
|
::caution
|
|
@@ -149,7 +163,7 @@ Be very careful before proxying headers to an external API and just include head
|
|
|
149
163
|
|
|
150
164
|
## `useFetch`
|
|
151
165
|
|
|
152
|
-
The [`useFetch`](/docs/
|
|
166
|
+
The [`useFetch`](/docs/api/composables/use-fetch) composable uses `$fetch` under-the-hood to make SSR-safe network calls in the setup function.
|
|
153
167
|
|
|
154
168
|
```vue twoslash [app/app.vue]
|
|
155
169
|
<script setup lang="ts">
|
|
@@ -161,13 +175,13 @@ const { data: count } = await useFetch('/api/count')
|
|
|
161
175
|
</template>
|
|
162
176
|
```
|
|
163
177
|
|
|
164
|
-
This composable is a wrapper around the [`useAsyncData`](/docs/
|
|
178
|
+
This composable is a wrapper around the [`useAsyncData`](/docs/api/composables/use-async-data) composable and `$fetch` utility.
|
|
165
179
|
|
|
166
180
|
:video-accordion{title="Watch a video from Alexander Lichter to avoid using useFetch the wrong way" videoId="njsGVmcWviY"}
|
|
167
181
|
|
|
168
|
-
:read-more{to="/docs/
|
|
182
|
+
:read-more{to="/docs/api/composables/use-fetch"}
|
|
169
183
|
|
|
170
|
-
:link-example{to="/docs/
|
|
184
|
+
:link-example{to="/docs/examples/features/data-fetching"}
|
|
171
185
|
|
|
172
186
|
## `useAsyncData`
|
|
173
187
|
|
|
@@ -175,12 +189,12 @@ The `useAsyncData` composable is responsible for wrapping async logic and return
|
|
|
175
189
|
|
|
176
190
|
::tip
|
|
177
191
|
`useFetch(url)` is nearly equivalent to `useAsyncData(url, () => event.$fetch(url))`. :br
|
|
178
|
-
It's developer experience sugar for the most common use case. (You can find out more about `event.fetch` at [`useRequestFetch`](/docs/
|
|
192
|
+
It's developer experience sugar for the most common use case. (You can find out more about `event.fetch` at [`useRequestFetch`](/docs/api/composables/use-request-fetch).)
|
|
179
193
|
::
|
|
180
194
|
|
|
181
195
|
:video-accordion{title="Watch a video from Alexander Lichter to dig deeper into the difference between useFetch and useAsyncData" videoId="0X-aOpSGabA"}
|
|
182
196
|
|
|
183
|
-
There are some cases when using the [`useFetch`](/docs/
|
|
197
|
+
There are some cases when using the [`useFetch`](/docs/api/composables/use-fetch) composable is not appropriate, for example when a CMS or a third-party provides their own query layer. In this case, you can use [`useAsyncData`](/docs/api/composables/use-async-data) to wrap your calls and still keep the benefits provided by the composable.
|
|
184
198
|
|
|
185
199
|
```vue [app/pages/users.vue]
|
|
186
200
|
<script setup lang="ts">
|
|
@@ -192,11 +206,11 @@ const { data, error } = await useAsyncData(() => myGetFunction('users'))
|
|
|
192
206
|
```
|
|
193
207
|
|
|
194
208
|
::note
|
|
195
|
-
The first argument of [`useAsyncData`](/docs/
|
|
209
|
+
The first argument of [`useAsyncData`](/docs/api/composables/use-async-data) is a unique key used to cache the response of the second argument, the querying function. This key can be ignored by directly passing the querying function, the key will be auto-generated.
|
|
196
210
|
:br :br
|
|
197
211
|
Since the autogenerated key only takes into account the location where `useAsyncData` is invoked, it is recommended to always create your own key to avoid unwanted behavior, like when you are creating your own custom composable wrapping `useAsyncData`.
|
|
198
212
|
:br :br
|
|
199
|
-
Setting a key can be useful to share the same data between components using [`useNuxtData`](/docs/
|
|
213
|
+
Setting a key can be useful to share the same data between components using [`useNuxtData`](/docs/api/composables/use-nuxt-data) or to [refresh specific data](/docs/api/utils/refresh-nuxt-data#refresh-specific-data).
|
|
200
214
|
::
|
|
201
215
|
|
|
202
216
|
```vue [app/pages/users/[id\\].vue]
|
|
@@ -227,7 +241,7 @@ const { data: discounts, status } = await useAsyncData('cart-discount', async (_
|
|
|
227
241
|
```
|
|
228
242
|
|
|
229
243
|
::note
|
|
230
|
-
`useAsyncData` is for fetching and caching data, not triggering side effects like calling Pinia actions, as this can cause unintended behavior such as repeated executions with nullish values. If you need to trigger side effects, use the [`callOnce`](/docs/
|
|
244
|
+
`useAsyncData` is for fetching and caching data, not triggering side effects like calling Pinia actions, as this can cause unintended behavior such as repeated executions with nullish values. If you need to trigger side effects, use the [`callOnce`](/docs/api/utils/call-once) utility to do so.
|
|
231
245
|
|
|
232
246
|
```vue
|
|
233
247
|
<script setup lang="ts">
|
|
@@ -239,7 +253,7 @@ await useAsyncData(() => offersStore.getOffer(route.params.slug))
|
|
|
239
253
|
```
|
|
240
254
|
::
|
|
241
255
|
|
|
242
|
-
::read-more{to="/docs/
|
|
256
|
+
::read-more{to="/docs/api/composables/use-async-data"}
|
|
243
257
|
Read more about `useAsyncData`.
|
|
244
258
|
::
|
|
245
259
|
|
|
@@ -265,7 +279,7 @@ If you have not fetched data on the server (for example, with `server: false`),
|
|
|
265
279
|
|
|
266
280
|
## Options
|
|
267
281
|
|
|
268
|
-
[`useAsyncData`](/docs/
|
|
282
|
+
[`useAsyncData`](/docs/api/composables/use-async-data) and [`useFetch`](/docs/api/composables/use-fetch) return the same object type and accept a common set of options as their last argument. They can help you control the composables behavior, such as navigation blocking, caching or execution.
|
|
269
283
|
|
|
270
284
|
### Lazy
|
|
271
285
|
|
|
@@ -291,7 +305,7 @@ const { status, data: posts } = useFetch('/api/posts', {
|
|
|
291
305
|
</template>
|
|
292
306
|
```
|
|
293
307
|
|
|
294
|
-
You can alternatively use [`useLazyFetch`](/docs/
|
|
308
|
+
You can alternatively use [`useLazyFetch`](/docs/api/composables/use-lazy-fetch) and `useLazyAsyncData` as convenient methods to perform the same.
|
|
295
309
|
|
|
296
310
|
```vue twoslash
|
|
297
311
|
<script setup lang="ts">
|
|
@@ -299,11 +313,11 @@ const { status, data: posts } = useLazyFetch('/api/posts')
|
|
|
299
313
|
</script>
|
|
300
314
|
```
|
|
301
315
|
|
|
302
|
-
::read-more{to="/docs/
|
|
316
|
+
::read-more{to="/docs/api/composables/use-lazy-fetch"}
|
|
303
317
|
Read more about `useLazyFetch`.
|
|
304
318
|
::
|
|
305
319
|
|
|
306
|
-
::read-more{to="/docs/
|
|
320
|
+
::read-more{to="/docs/api/composables/use-lazy-async-data"}
|
|
307
321
|
Read more about `useLazyAsyncData`.
|
|
308
322
|
::
|
|
309
323
|
|
|
@@ -326,7 +340,7 @@ const { status, data: comments } = useFetch('/api/comments', {
|
|
|
326
340
|
})
|
|
327
341
|
```
|
|
328
342
|
|
|
329
|
-
The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](/docs/
|
|
343
|
+
The `useFetch` composable is meant to be invoked in setup method or called directly at the top level of a function in lifecycle hooks, otherwise you should use [`$fetch` method](/docs/getting-started/data-fetching#fetch).
|
|
330
344
|
|
|
331
345
|
### Minimize payload size
|
|
332
346
|
|
|
@@ -366,13 +380,13 @@ Both `pick` and `transform` don't prevent the unwanted data from being fetched i
|
|
|
366
380
|
|
|
367
381
|
#### Keys
|
|
368
382
|
|
|
369
|
-
[`useFetch`](/docs/
|
|
383
|
+
[`useFetch`](/docs/api/composables/use-fetch) and [`useAsyncData`](/docs/api/composables/use-async-data) use keys to prevent refetching the same data.
|
|
370
384
|
|
|
371
|
-
- [`useFetch`](/docs/
|
|
372
|
-
- [`useAsyncData`](/docs/
|
|
385
|
+
- [`useFetch`](/docs/api/composables/use-fetch) generates a key from the URL, the fetch options and the location of the call in your source code. This means two `useFetch` calls with the same URL in different components have **different** keys and will each perform their own request. To share the same data between multiple components, provide the same explicit `key` in the `options` object passed as a last argument.
|
|
386
|
+
- [`useAsyncData`](/docs/api/composables/use-async-data) uses its first argument as a key if it is a string. If the first argument is the handler function that performs the query, then a key that is unique to the location of the `useAsyncData` call in your source code will be generated for you.
|
|
373
387
|
|
|
374
388
|
::tip
|
|
375
|
-
To get the cached data by key, you can use [`useNuxtData`](/docs/
|
|
389
|
+
To get the cached data by key, you can use [`useNuxtData`](/docs/api/composables/use-nuxt-data)
|
|
376
390
|
::
|
|
377
391
|
|
|
378
392
|
:video-accordion{title="Watch a video from Vue School on caching data with the key option" videoId="1026410044" platform="vimeo"}
|
|
@@ -452,10 +466,10 @@ const { data, error, execute, refresh } = await useFetch('/api/users')
|
|
|
452
466
|
</template>
|
|
453
467
|
```
|
|
454
468
|
|
|
455
|
-
The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](/docs/
|
|
469
|
+
The `execute` function is an alias for `refresh` that works in exactly the same way but is more semantic for cases when the fetch is [not immediate](/docs/getting-started/data-fetching#not-immediate).
|
|
456
470
|
|
|
457
471
|
::tip
|
|
458
|
-
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/
|
|
472
|
+
To globally refetch or invalidate cached data, see [`clearNuxtData`](/docs/api/utils/clear-nuxt-data) and [`refreshNuxtData`](/docs/api/utils/refresh-nuxt-data).
|
|
459
473
|
::
|
|
460
474
|
|
|
461
475
|
#### Clear
|
|
@@ -502,7 +516,7 @@ const { data, error, refresh } = await useFetch(`/api/users/${id.value}`, {
|
|
|
502
516
|
</script>
|
|
503
517
|
```
|
|
504
518
|
|
|
505
|
-
If you need to change the URL based on a reactive value, you may want to use a [computed URL](/docs/
|
|
519
|
+
If you need to change the URL based on a reactive value, you may want to use a [computed URL](/docs/getting-started/data-fetching#computed-url) instead.
|
|
506
520
|
|
|
507
521
|
When reactive fetch options are provided, they'll be automatically watched and trigger refetches. In some cases, it can be useful to opt-out of this behavior by specifying `watch: false`.
|
|
508
522
|
|
|
@@ -537,7 +551,7 @@ const { data, status } = useLazyFetch('/api/user', {
|
|
|
537
551
|
|
|
538
552
|
In the case of more complex URL construction, you may use a callback as a [computed getter](https://vuejs.org/guide/essentials/computed) that returns the URL string.
|
|
539
553
|
|
|
540
|
-
Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](/docs/
|
|
554
|
+
Every time a dependency changes, the data will be fetched using the newly constructed URL. Combine this with [not-immediate](/docs/getting-started/data-fetching#not-immediate), and you can wait until the reactive element changes before fetching.
|
|
541
555
|
|
|
542
556
|
```vue
|
|
543
557
|
<script setup lang="ts">
|
|
@@ -572,11 +586,11 @@ const { data, status } = useLazyFetch(() => `/api/users/${id.value}`, {
|
|
|
572
586
|
</template>
|
|
573
587
|
```
|
|
574
588
|
|
|
575
|
-
If you need to force a refresh when other reactive values change, you can also [watch other values](/docs/
|
|
589
|
+
If you need to force a refresh when other reactive values change, you can also [watch other values](/docs/getting-started/data-fetching#watch).
|
|
576
590
|
|
|
577
591
|
### Not immediate
|
|
578
592
|
|
|
579
|
-
The `useFetch` composable will start fetching data the moment is invoked. You may prevent this by setting `immediate: false`, for example, to wait for user interaction.
|
|
593
|
+
The `useFetch` composable will start fetching data the moment it is invoked. You may prevent this by setting `immediate: false`, for example, to wait for user interaction.
|
|
580
594
|
|
|
581
595
|
With that, you will need both the `status` to handle the fetch lifecycle, and `execute` to start the data fetch.
|
|
582
596
|
|
|
@@ -617,7 +631,7 @@ When we call `$fetch` in the browser, user headers like `cookie` will be directl
|
|
|
617
631
|
|
|
618
632
|
Normally, during server-side-rendering, due to security considerations, the `$fetch` wouldn't include the user's browser cookies, nor pass on cookies from the fetch response.
|
|
619
633
|
|
|
620
|
-
However, when calling `useFetch` with a relative URL on the server, Nuxt will use [`useRequestFetch`](/docs/
|
|
634
|
+
However, when calling `useFetch` with a relative URL on the server, Nuxt will use [`useRequestFetch`](/docs/api/composables/use-request-fetch) to proxy headers and cookies (with the exception of headers not meant to be forwarded, like `host`).
|
|
621
635
|
|
|
622
636
|
### Pass Cookies From Server-side API Calls on SSR Response
|
|
623
637
|
|
|
@@ -674,13 +688,13 @@ export default defineNuxtComponent({
|
|
|
674
688
|
Using `<script setup>` or `<script setup lang="ts">` are the recommended way of declaring Vue components in Nuxt.
|
|
675
689
|
::
|
|
676
690
|
|
|
677
|
-
:read-more{to="/docs/
|
|
691
|
+
:read-more{to="/docs/api/utils/define-nuxt-component"}
|
|
678
692
|
|
|
679
693
|
## Serializing Data From Server to Client
|
|
680
694
|
|
|
681
|
-
When using `useAsyncData` and `useLazyAsyncData` to transfer data fetched on server to the client (as well as anything else that utilizes [the Nuxt payload](/docs/
|
|
695
|
+
When using `useAsyncData` and `useLazyAsyncData` to transfer data fetched on server to the client (as well as anything else that utilizes [the Nuxt payload](/docs/api/composables/use-nuxt-app#payload)), the payload is serialized with [`devalue`](https://github.com/sveltejs/devalue). This allows us to transfer not just basic JSON but also to serialize and revive/deserialize more advanced kinds of data, such as regular expressions, Dates, Map and Set, `ref`, `reactive`, `shallowRef`, `shallowReactive` and `NuxtError` - and more.
|
|
682
696
|
|
|
683
|
-
It is also possible to define your own serializer/deserializer for types that are not supported by Nuxt. You can read more in the [`useNuxtApp`](/docs/
|
|
697
|
+
It is also possible to define your own serializer/deserializer for types that are not supported by Nuxt. You can read more in the [`useNuxtApp`](/docs/api/composables/use-nuxt-app#payload) docs.
|
|
684
698
|
|
|
685
699
|
::note
|
|
686
700
|
Note that this *does not apply* to data passed from your server routes when fetched with `$fetch` or `useFetch` - see the next section for more information.
|
|
@@ -688,7 +702,7 @@ Note that this *does not apply* to data passed from your server routes when fetc
|
|
|
688
702
|
|
|
689
703
|
## Serializing Data From API Routes
|
|
690
704
|
|
|
691
|
-
When fetching data from the `server` directory, the response is serialized using `JSON.stringify`. However, since serialization is limited to only JavaScript primitive types, Nuxt does its best to convert the return type of `$fetch` and [`useFetch`](/docs/
|
|
705
|
+
When fetching data from the `server` directory, the response is serialized using `JSON.stringify`. However, since serialization is limited to only JavaScript primitive types, Nuxt does its best to convert the return type of `$fetch` and [`useFetch`](/docs/api/composables/use-fetch) to match the actual value.
|
|
692
706
|
|
|
693
707
|
::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#description" target="_blank"}
|
|
694
708
|
Learn more about `JSON.stringify` limitations.
|
|
@@ -4,17 +4,17 @@ description: Nuxt provides powerful state management libraries and the useState
|
|
|
4
4
|
navigation.icon: i-lucide-database
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
Nuxt provides the [`useState`](/docs/
|
|
7
|
+
Nuxt provides the [`useState`](/docs/api/composables/use-state) composable to create a reactive and SSR-friendly shared state across components.
|
|
8
8
|
|
|
9
|
-
[`useState`](/docs/
|
|
9
|
+
[`useState`](/docs/api/composables/use-state) is an SSR-friendly [`ref`](https://vuejs.org/api/reactivity-core#ref) replacement. Its value will be preserved after server-side rendering (during client-side hydration) and shared across all components using a unique key.
|
|
10
10
|
|
|
11
11
|
:video-accordion{title="Watch a video from Alexander Lichter about why and when to use useState" videoId="mv0WcBABcIk"}
|
|
12
12
|
|
|
13
13
|
::important
|
|
14
|
-
Because the data inside [`useState`](/docs/
|
|
14
|
+
Because the data inside [`useState`](/docs/api/composables/use-state) will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
|
|
15
15
|
::
|
|
16
16
|
|
|
17
|
-
::read-more{to="/docs/
|
|
17
|
+
::read-more{to="/docs/api/composables/use-state"}
|
|
18
18
|
Read more about `useState` composable.
|
|
19
19
|
::
|
|
20
20
|
|
|
@@ -53,15 +53,15 @@ const counter = useState('counter', () => Math.round(Math.random() * 1000))
|
|
|
53
53
|
</template>
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
:link-example{to="/docs/
|
|
56
|
+
:link-example{to="/docs/examples/features/state-management"}
|
|
57
57
|
|
|
58
58
|
::note
|
|
59
|
-
To globally invalidate cached state, see [`clearNuxtState`](/docs/
|
|
59
|
+
To globally invalidate cached state, see [`clearNuxtState`](/docs/api/utils/clear-nuxt-state) util.
|
|
60
60
|
::
|
|
61
61
|
|
|
62
62
|
### Initializing State
|
|
63
63
|
|
|
64
|
-
Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/
|
|
64
|
+
Most of the time, you will want to initialize your state with data that resolves asynchronously. You can use the [`app.vue`](/docs/directory-structure/app/app) component with the [`callOnce`](/docs/api/utils/call-once) util to do so.
|
|
65
65
|
|
|
66
66
|
```vue twoslash [app/app.vue]
|
|
67
67
|
<script setup lang="ts">
|
|
@@ -77,7 +77,7 @@ await callOnce(async () => {
|
|
|
77
77
|
This is similar to the [`nuxtServerInit` action](https://v2.nuxt.com/docs/directory-structure/store/#the-nuxtserverinit-action) in Nuxt 2, which allows filling the initial state of your store server-side before rendering the page.
|
|
78
78
|
::
|
|
79
79
|
|
|
80
|
-
:read-more{to="/docs/
|
|
80
|
+
:read-more{to="/docs/api/utils/call-once"}
|
|
81
81
|
|
|
82
82
|
### Usage with Pinia
|
|
83
83
|
|
|
@@ -194,11 +194,11 @@ const date = useLocaleDate(new Date('2016-10-26'))
|
|
|
194
194
|
```
|
|
195
195
|
::
|
|
196
196
|
|
|
197
|
-
:link-example{to="/docs/
|
|
197
|
+
:link-example{to="/docs/examples/advanced/locale"}
|
|
198
198
|
|
|
199
199
|
## Shared State
|
|
200
200
|
|
|
201
|
-
By using [auto-imported composables](/docs/
|
|
201
|
+
By using [auto-imported composables](/docs/directory-structure/app/composables) we can define global type-safe states and import them across the app.
|
|
202
202
|
|
|
203
203
|
```ts twoslash [composables/states.ts]
|
|
204
204
|
export const useColor = () => useState<string>('color', () => 'pink')
|
|
@@ -221,7 +221,7 @@ const color = useColor() // Same as useState('color')
|
|
|
221
221
|
|
|
222
222
|
## Using Third-Party Libraries
|
|
223
223
|
|
|
224
|
-
Nuxt **used to rely** on the Vuex library to provide global state management. If you are migrating from Nuxt 2, please head to [the migration guide](/docs/
|
|
224
|
+
Nuxt **used to rely** on the Vuex library to provide global state management. If you are migrating from Nuxt 2, please head to [the migration guide](/docs/migration/configuration#vuex).
|
|
225
225
|
|
|
226
226
|
Nuxt is not opinionated about state management, so feel free to choose the right solution for your needs. There are multiple integrations with the most popular state management libraries, including:
|
|
227
227
|
|