@nuxt/docs 0.0.0 → 3.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.navigation.yml +2 -0
- package/1.getting-started/.navigation.yml +3 -0
- package/1.getting-started/01.introduction.md +81 -0
- package/1.getting-started/02.installation.md +109 -0
- package/1.getting-started/03.configuration.md +226 -0
- package/1.getting-started/04.views.md +163 -0
- package/1.getting-started/05.assets.md +48 -0
- package/1.getting-started/06.styling.md +565 -0
- package/1.getting-started/07.routing.md +149 -0
- package/1.getting-started/08.seo-meta.md +360 -0
- package/1.getting-started/09.transitions.md +473 -0
- package/1.getting-started/10.data-fetching.md +795 -0
- package/1.getting-started/11.state-management.md +223 -0
- package/1.getting-started/12.error-handling.md +233 -0
- package/1.getting-started/13.server.md +94 -0
- package/1.getting-started/14.layers.md +92 -0
- package/1.getting-started/15.prerendering.md +194 -0
- package/1.getting-started/16.deployment.md +130 -0
- package/1.getting-started/17.testing.md +728 -0
- package/1.getting-started/18.upgrade.md +997 -0
- package/2.guide/.navigation.yml +2 -0
- package/2.guide/0.index.md +22 -0
- package/2.guide/1.concepts/.navigation.yml +3 -0
- package/2.guide/1.concepts/1.auto-imports.md +205 -0
- package/2.guide/1.concepts/10.nuxt-lifecycle.md +141 -0
- package/2.guide/1.concepts/2.vuejs-development.md +103 -0
- package/2.guide/1.concepts/3.rendering.md +255 -0
- package/2.guide/1.concepts/4.server-engine.md +62 -0
- package/2.guide/1.concepts/5.modules.md +48 -0
- package/2.guide/1.concepts/7.esm.md +299 -0
- package/2.guide/1.concepts/8.typescript.md +97 -0
- package/2.guide/1.concepts/9.code-style.md +22 -0
- package/2.guide/2.directory-structure/.navigation.yml +3 -0
- package/2.guide/2.directory-structure/0.nuxt.md +20 -0
- package/2.guide/2.directory-structure/0.output.md +18 -0
- package/2.guide/2.directory-structure/1.assets.md +16 -0
- package/2.guide/2.directory-structure/1.components.md +608 -0
- package/2.guide/2.directory-structure/1.composables.md +121 -0
- package/2.guide/2.directory-structure/1.content.md +64 -0
- package/2.guide/2.directory-structure/1.layouts.md +180 -0
- package/2.guide/2.directory-structure/1.middleware.md +209 -0
- package/2.guide/2.directory-structure/1.modules.md +66 -0
- package/2.guide/2.directory-structure/1.node_modules.md +12 -0
- package/2.guide/2.directory-structure/1.pages.md +440 -0
- package/2.guide/2.directory-structure/1.plugins.md +299 -0
- package/2.guide/2.directory-structure/1.public.md +27 -0
- package/2.guide/2.directory-structure/1.server.md +546 -0
- package/2.guide/2.directory-structure/1.shared.md +104 -0
- package/2.guide/2.directory-structure/1.utils.md +49 -0
- package/2.guide/2.directory-structure/2.env.md +75 -0
- package/2.guide/2.directory-structure/2.gitignore.md +37 -0
- package/2.guide/2.directory-structure/2.nuxtignore.md +36 -0
- package/2.guide/2.directory-structure/2.nuxtrc.md +50 -0
- package/2.guide/2.directory-structure/3.app-config.md +177 -0
- package/2.guide/2.directory-structure/3.app.md +72 -0
- package/2.guide/2.directory-structure/3.error.md +55 -0
- package/2.guide/2.directory-structure/3.nuxt-config.md +34 -0
- package/2.guide/2.directory-structure/3.package.md +32 -0
- package/2.guide/2.directory-structure/3.tsconfig.md +24 -0
- package/2.guide/3.going-further/.navigation.yml +3 -0
- package/2.guide/3.going-further/1.experimental-features.md +689 -0
- package/2.guide/3.going-further/1.features.md +103 -0
- package/2.guide/3.going-further/1.internals.md +81 -0
- package/2.guide/3.going-further/10.runtime-config.md +174 -0
- package/2.guide/3.going-further/11.nightly-release-channel.md +68 -0
- package/2.guide/3.going-further/2.hooks.md +98 -0
- package/2.guide/3.going-further/3.modules.md +811 -0
- package/2.guide/3.going-further/4.kit.md +51 -0
- package/2.guide/3.going-further/6.nuxt-app.md +64 -0
- package/2.guide/3.going-further/7.layers.md +227 -0
- package/2.guide/3.going-further/9.debugging.md +115 -0
- package/2.guide/3.going-further/index.md +4 -0
- package/2.guide/4.recipes/.navigation.yml +3 -0
- package/2.guide/4.recipes/1.custom-routing.md +181 -0
- package/2.guide/4.recipes/2.vite-plugin.md +65 -0
- package/2.guide/4.recipes/3.custom-usefetch.md +125 -0
- package/2.guide/4.recipes/4.sessions-and-authentication.md +203 -0
- package/3.api/.navigation.yml +3 -0
- package/3.api/1.components/.navigation.yml +3 -0
- package/3.api/1.components/1.client-only.md +76 -0
- package/3.api/1.components/1.dev-only.md +51 -0
- package/3.api/1.components/1.nuxt-client-fallback.md +80 -0
- package/3.api/1.components/10.nuxt-picture.md +27 -0
- package/3.api/1.components/11.teleports.md +40 -0
- package/3.api/1.components/12.nuxt-route-announcer.md +56 -0
- package/3.api/1.components/13.nuxt-time.md +173 -0
- package/3.api/1.components/2.nuxt-page.md +154 -0
- package/3.api/1.components/3.nuxt-layout.md +156 -0
- package/3.api/1.components/4.nuxt-link.md +322 -0
- package/3.api/1.components/5.nuxt-loading-indicator.md +50 -0
- package/3.api/1.components/6.nuxt-error-boundary.md +65 -0
- package/3.api/1.components/7.nuxt-welcome.md +25 -0
- package/3.api/1.components/8.nuxt-island.md +70 -0
- package/3.api/1.components/9.nuxt-img.md +43 -0
- package/3.api/2.composables/.navigation.yml +3 -0
- package/3.api/2.composables/on-prehydrate.md +60 -0
- package/3.api/2.composables/use-app-config.md +19 -0
- package/3.api/2.composables/use-async-data.md +212 -0
- package/3.api/2.composables/use-cookie.md +233 -0
- package/3.api/2.composables/use-error.md +32 -0
- package/3.api/2.composables/use-fetch.md +217 -0
- package/3.api/2.composables/use-head-safe.md +55 -0
- package/3.api/2.composables/use-head.md +69 -0
- package/3.api/2.composables/use-hydration.md +68 -0
- package/3.api/2.composables/use-lazy-async-data.md +47 -0
- package/3.api/2.composables/use-lazy-fetch.md +55 -0
- package/3.api/2.composables/use-loading-indicator.md +77 -0
- package/3.api/2.composables/use-nuxt-app.md +294 -0
- package/3.api/2.composables/use-nuxt-data.md +112 -0
- package/3.api/2.composables/use-preview-mode.md +118 -0
- package/3.api/2.composables/use-request-event.md +23 -0
- package/3.api/2.composables/use-request-fetch.md +52 -0
- package/3.api/2.composables/use-request-header.md +34 -0
- package/3.api/2.composables/use-request-headers.md +37 -0
- package/3.api/2.composables/use-request-url.md +41 -0
- package/3.api/2.composables/use-response-header.md +48 -0
- package/3.api/2.composables/use-route-announcer.md +60 -0
- package/3.api/2.composables/use-route.md +52 -0
- package/3.api/2.composables/use-router.md +92 -0
- package/3.api/2.composables/use-runtime-config.md +142 -0
- package/3.api/2.composables/use-runtime-hook.md +43 -0
- package/3.api/2.composables/use-seo-meta.md +80 -0
- package/3.api/2.composables/use-server-seo-meta.md +27 -0
- package/3.api/2.composables/use-state.md +48 -0
- package/3.api/3.utils/$fetch.md +98 -0
- package/3.api/3.utils/.navigation.yml +3 -0
- package/3.api/3.utils/abort-navigation.md +73 -0
- package/3.api/3.utils/add-route-middleware.md +88 -0
- package/3.api/3.utils/call-once.md +92 -0
- package/3.api/3.utils/clear-error.md +29 -0
- package/3.api/3.utils/clear-nuxt-data.md +23 -0
- package/3.api/3.utils/clear-nuxt-state.md +23 -0
- package/3.api/3.utils/create-error.md +55 -0
- package/3.api/3.utils/define-nuxt-component.md +53 -0
- package/3.api/3.utils/define-nuxt-route-middleware.md +67 -0
- package/3.api/3.utils/define-page-meta.md +234 -0
- package/3.api/3.utils/define-route-rules.md +52 -0
- package/3.api/3.utils/navigate-to.md +230 -0
- package/3.api/3.utils/on-before-route-leave.md +11 -0
- package/3.api/3.utils/on-before-route-update.md +11 -0
- package/3.api/3.utils/on-nuxt-ready.md +25 -0
- package/3.api/3.utils/prefetch-components.md +28 -0
- package/3.api/3.utils/preload-components.md +23 -0
- package/3.api/3.utils/preload-route-components.md +41 -0
- package/3.api/3.utils/prerender-routes.md +46 -0
- package/3.api/3.utils/refresh-cookie.md +46 -0
- package/3.api/3.utils/refresh-nuxt-data.md +91 -0
- package/3.api/3.utils/reload-nuxt-app.md +74 -0
- package/3.api/3.utils/set-page-layout.md +24 -0
- package/3.api/3.utils/set-response-status.md +36 -0
- package/3.api/3.utils/show-error.md +31 -0
- package/3.api/3.utils/update-app-config.md +27 -0
- package/3.api/4.commands/.navigation.yml +3 -0
- package/3.api/4.commands/add.md +112 -0
- package/3.api/4.commands/analyze.md +41 -0
- package/3.api/4.commands/build-module.md +42 -0
- package/3.api/4.commands/build.md +46 -0
- package/3.api/4.commands/cleanup.md +38 -0
- package/3.api/4.commands/dev.md +59 -0
- package/3.api/4.commands/devtools.md +38 -0
- package/3.api/4.commands/generate.md +41 -0
- package/3.api/4.commands/info.md +33 -0
- package/3.api/4.commands/init.md +46 -0
- package/3.api/4.commands/module.md +84 -0
- package/3.api/4.commands/prepare.md +36 -0
- package/3.api/4.commands/preview.md +43 -0
- package/3.api/4.commands/typecheck.md +42 -0
- package/3.api/4.commands/upgrade.md +37 -0
- package/3.api/5.kit/.navigation.yml +3 -0
- package/3.api/5.kit/1.modules.md +172 -0
- package/3.api/5.kit/10.runtime-config.md +27 -0
- package/3.api/5.kit/10.templates.md +283 -0
- package/3.api/5.kit/11.nitro.md +409 -0
- package/3.api/5.kit/12.resolving.md +268 -0
- package/3.api/5.kit/13.logging.md +65 -0
- package/3.api/5.kit/14.builder.md +491 -0
- package/3.api/5.kit/15.examples.md +41 -0
- package/3.api/5.kit/2.programmatic.md +125 -0
- package/3.api/5.kit/3.compatibility.md +230 -0
- package/3.api/5.kit/4.autoimports.md +144 -0
- package/3.api/5.kit/5.components.md +127 -0
- package/3.api/5.kit/6.context.md +130 -0
- package/3.api/5.kit/7.pages.md +295 -0
- package/3.api/5.kit/8.layout.md +80 -0
- package/3.api/5.kit/9.plugins.md +263 -0
- package/3.api/6.advanced/.navigation.yml +1 -0
- package/3.api/6.advanced/1.hooks.md +105 -0
- package/3.api/6.advanced/2.import-meta.md +60 -0
- package/3.api/6.nuxt-config.md +12 -0
- package/3.api/index.md +31 -0
- package/5.community/.navigation.yml +3 -0
- package/5.community/2.getting-help.md +48 -0
- package/5.community/3.reporting-bugs.md +50 -0
- package/5.community/4.contribution.md +205 -0
- package/5.community/5.framework-contribution.md +142 -0
- package/5.community/6.roadmap.md +79 -0
- package/5.community/7.changelog.md +92 -0
- package/6.bridge/.navigation.yml +3 -0
- package/6.bridge/1.overview.md +137 -0
- package/6.bridge/10.configuration.md +96 -0
- package/6.bridge/2.typescript.md +46 -0
- package/6.bridge/3.bridge-composition-api.md +132 -0
- package/6.bridge/4.plugins-and-middleware.md +65 -0
- package/6.bridge/5.nuxt3-compatible-api.md +204 -0
- package/6.bridge/6.meta.md +117 -0
- package/6.bridge/7.runtime-config.md +38 -0
- package/6.bridge/8.nitro.md +102 -0
- package/6.bridge/9.vite.md +37 -0
- package/7.migration/.navigation.yml +3 -0
- package/7.migration/1.overview.md +24 -0
- package/7.migration/10.bundling.md +28 -0
- package/7.migration/11.server.md +17 -0
- package/7.migration/2.configuration.md +240 -0
- package/7.migration/20.module-authors.md +94 -0
- package/7.migration/3.auto-imports.md +18 -0
- package/7.migration/4.meta.md +127 -0
- package/7.migration/5.plugins-and-middleware.md +80 -0
- package/7.migration/6.pages-and-layouts.md +233 -0
- package/7.migration/7.component-options.md +156 -0
- package/7.migration/8.runtime-config.md +58 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/package.json +16 -4
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useRequestURL'
|
|
3
|
+
description: 'Access the incoming request URL with the useRequestURL composable.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/url.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
`useRequestURL` is a helper function that returns an [URL object](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) working on both server-side and client-side.
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
When utilizing [Hybrid Rendering](/docs/guide/concepts/rendering#hybrid-rendering) with cache strategies, all incoming request headers are dropped when handling the cached responses via the [Nitro caching layer](https://nitro.unjs.io/guide/cache) (meaning `useRequestURL` will return `localhost` for the `host`).
|
|
15
|
+
|
|
16
|
+
You can define the [`cache.varies` option](https://nitro.unjs.io/guide/cache#options) to specify headers that will be considered when caching and serving the responses, such as `host` and `x-forwarded-host` for multi-tenant environments.
|
|
17
|
+
::
|
|
18
|
+
|
|
19
|
+
::code-group
|
|
20
|
+
|
|
21
|
+
```vue [pages/about.vue]
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
const url = useRequestURL()
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<p>URL is: {{ url }}</p>
|
|
28
|
+
<p>Path is: {{ url.pathname }}</p>
|
|
29
|
+
</template>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
```html [Result in development]
|
|
33
|
+
<p>URL is: http://localhost:3000/about</p>
|
|
34
|
+
<p>Path is: /about</p>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
::
|
|
38
|
+
|
|
39
|
+
::tip{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/URL#instance_properties" target="_blank"}
|
|
40
|
+
Read about the URL instance properties on the MDN documentation.
|
|
41
|
+
::
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useResponseHeader"
|
|
3
|
+
description: "Use useResponseHeader to set a server response header."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::important
|
|
12
|
+
This composable is available in Nuxt v3.14+.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
You can use the built-in [`useResponseHeader`](/docs/api/composables/use-response-header) composable to set any server response header within your pages, components, and plugins.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
// Set the a custom response header
|
|
19
|
+
const header = useResponseHeader('X-My-Header');
|
|
20
|
+
header.value = 'my-value';
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Example
|
|
24
|
+
|
|
25
|
+
We can use `useResponseHeader` to easily set a response header on a per-page basis.
|
|
26
|
+
|
|
27
|
+
```vue [pages/test.vue]
|
|
28
|
+
<script setup>
|
|
29
|
+
// pages/test.vue
|
|
30
|
+
const header = useResponseHeader('X-My-Header');
|
|
31
|
+
header.value = 'my-value';
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<template>
|
|
35
|
+
<h1>Test page with custom header</h1>
|
|
36
|
+
<p>The response from the server for this "/test" page will have a custom "X-My-Header" header.</p>
|
|
37
|
+
</template>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/guide/directory-structure/middleware) to set a response header for all pages.
|
|
41
|
+
|
|
42
|
+
```ts [middleware/my-header-middleware.ts]
|
|
43
|
+
export default defineNuxtRouteMiddleware((to, from) => {
|
|
44
|
+
const header = useResponseHeader('X-My-Always-Header');
|
|
45
|
+
header.value = `I'm Always here!`;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
```
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useRouteAnnouncer'
|
|
3
|
+
description: This composable observes the page title changes and updates the announcer message accordingly.
|
|
4
|
+
navigation:
|
|
5
|
+
badge: New
|
|
6
|
+
links:
|
|
7
|
+
- label: Source
|
|
8
|
+
icon: i-simple-icons-github
|
|
9
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/route-announcer.ts
|
|
10
|
+
size: xs
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
This composable is available in Nuxt v3.12+.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
## Description
|
|
18
|
+
|
|
19
|
+
A composable which observes the page title changes and updates the announcer message accordingly. Used by [`<NuxtRouteAnnouncer>`](/docs/api/components/nuxt-route-announcer) and controllable.
|
|
20
|
+
It hooks into Unhead's [`dom:rendered`](https://unhead.unjs.io/docs/typescript/head/api/hooks/dom-rendered) to read the page's title and set it as the announcer message.
|
|
21
|
+
|
|
22
|
+
## Parameters
|
|
23
|
+
|
|
24
|
+
- `politeness`: Sets the urgency for screen reader announcements: `off` (disable the announcement), `polite` (waits for silence), or `assertive` (interrupts immediately). (default `polite`).
|
|
25
|
+
|
|
26
|
+
## Properties
|
|
27
|
+
|
|
28
|
+
### `message`
|
|
29
|
+
|
|
30
|
+
- **type**: `Ref<string>`
|
|
31
|
+
- **description**: The message to announce
|
|
32
|
+
|
|
33
|
+
### `politeness`
|
|
34
|
+
|
|
35
|
+
- **type**: `Ref<string>`
|
|
36
|
+
- **description**: Screen reader announcement urgency level `off`, `polite`, or `assertive`
|
|
37
|
+
|
|
38
|
+
## Methods
|
|
39
|
+
|
|
40
|
+
### `set(message, politeness = "polite")`
|
|
41
|
+
|
|
42
|
+
Sets the message to announce with its urgency level.
|
|
43
|
+
|
|
44
|
+
### `polite(message)`
|
|
45
|
+
|
|
46
|
+
Sets the message with `politeness = "polite"`
|
|
47
|
+
|
|
48
|
+
### `assertive(message)`
|
|
49
|
+
|
|
50
|
+
Sets the message with `politeness = "assertive"`
|
|
51
|
+
|
|
52
|
+
## Example
|
|
53
|
+
|
|
54
|
+
```vue [pages/index.vue]
|
|
55
|
+
<script setup lang="ts">
|
|
56
|
+
const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
|
|
57
|
+
politeness: 'assertive'
|
|
58
|
+
})
|
|
59
|
+
</script>
|
|
60
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useRoute"
|
|
3
|
+
description: The useRoute composable returns the current route.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::note
|
|
12
|
+
Within the template of a Vue component, you can access the route using `$route`.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
In the following example, we call an API via [`useFetch`](/docs/api/composables/use-fetch) using a dynamic page parameter - `slug` - as part of the URL.
|
|
18
|
+
|
|
19
|
+
```html [~/pages/[slug\\].vue]
|
|
20
|
+
<script setup lang="ts">
|
|
21
|
+
const route = useRoute()
|
|
22
|
+
const { data: mountain } = await useFetch(`/api/mountains/${route.params.slug}`)
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<div>
|
|
27
|
+
<h1>{{ mountain.title }}</h1>
|
|
28
|
+
<p>{{ mountain.description }}</p>
|
|
29
|
+
</div>
|
|
30
|
+
</template>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
If you need to access the route query parameters (for example `example` in the path `/test?example=true`), then you can use `useRoute().query` instead of `useRoute().params`.
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
Apart from dynamic parameters and query parameters, `useRoute()` also provides the following computed references related to the current route:
|
|
38
|
+
|
|
39
|
+
- `fullPath`: encoded URL associated with the current route that contains path, query and hash
|
|
40
|
+
- `hash`: decoded hash section of the URL that starts with a #
|
|
41
|
+
- `query`: access route query parameters
|
|
42
|
+
- `matched`: array of normalized matched routes with current route location
|
|
43
|
+
- `meta`: custom data attached to the record
|
|
44
|
+
- `name`: unique name for the route record
|
|
45
|
+
- `path`: encoded pathname section of the URL
|
|
46
|
+
- `redirectedFrom`: route location that was attempted to access before ending up on the current route location
|
|
47
|
+
|
|
48
|
+
::note
|
|
49
|
+
Browsers don't send [URL fragments](https://url.spec.whatwg.org/#concept-url-fragment) (for example `#foo`) when making requests. So using `route.fullPath` in your template can trigger hydration issues because this will include the fragment on client but not the server.
|
|
50
|
+
::
|
|
51
|
+
|
|
52
|
+
:read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/#RouteLocationNormalizedLoaded"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useRouter"
|
|
3
|
+
description: "The useRouter composable returns the router instance."
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/router.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
```vue [pages/index.vue]
|
|
12
|
+
<script setup lang="ts">
|
|
13
|
+
const router = useRouter()
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
If you only need the router instance within your template, use `$router`:
|
|
18
|
+
|
|
19
|
+
```vue [pages/index.vue]
|
|
20
|
+
<template>
|
|
21
|
+
<button @click="$router.back()">Back</button>
|
|
22
|
+
</template>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
If you have a `pages/` directory, `useRouter` is identical in behavior to the one provided by `vue-router`.
|
|
26
|
+
|
|
27
|
+
::read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/interfaces/Router.html#Properties-currentRoute" target="_blank"}
|
|
28
|
+
Read `vue-router` documentation about the `Router` interface.
|
|
29
|
+
::
|
|
30
|
+
|
|
31
|
+
## Basic Manipulation
|
|
32
|
+
|
|
33
|
+
- [`addRoute()`](https://router.vuejs.org/api/interfaces/Router.html#addRoute): Add a new route to the router instance. `parentName` can be provided to add new route as the child of an existing route.
|
|
34
|
+
- [`removeRoute()`](https://router.vuejs.org/api/interfaces/Router.html#removeRoute): Remove an existing route by its name.
|
|
35
|
+
- [`getRoutes()`](https://router.vuejs.org/api/interfaces/Router.html#getRoutes): Get a full list of all the route records.
|
|
36
|
+
- [`hasRoute()`](https://router.vuejs.org/api/interfaces/Router.html#hasRoute): Checks if a route with a given name exists.
|
|
37
|
+
- [`resolve()`](https://router.vuejs.org/api/interfaces/Router.html#resolve): Returns the normalized version of a route location. Also includes an `href` property that includes any existing base.
|
|
38
|
+
|
|
39
|
+
```ts [Example]
|
|
40
|
+
const router = useRouter()
|
|
41
|
+
|
|
42
|
+
router.addRoute({ name: 'home', path: '/home', component: Home })
|
|
43
|
+
router.removeRoute('home')
|
|
44
|
+
router.getRoutes()
|
|
45
|
+
router.hasRoute('home')
|
|
46
|
+
router.resolve({ name: 'home' })
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
::note
|
|
50
|
+
`router.addRoute()` adds route details into an array of routes and it is useful while building [Nuxt plugins](/docs/guide/directory-structure/plugins) while `router.push()` on the other hand, triggers a new navigation immediately and it is useful in pages, Vue components and composable.
|
|
51
|
+
::
|
|
52
|
+
|
|
53
|
+
## Based on History API
|
|
54
|
+
|
|
55
|
+
- [`back()`](https://router.vuejs.org/api/interfaces/Router.html#back): Go back in history if possible, same as `router.go(-1)`.
|
|
56
|
+
- [`forward()`](https://router.vuejs.org/api/interfaces/Router.html#forward): Go forward in history if possible, same as `router.go(1)`.
|
|
57
|
+
- [`go()`](https://router.vuejs.org/api/interfaces/Router.html#go): Move forward or backward through the history without the hierarchical restrictions enforced in `router.back()` and `router.forward()`.
|
|
58
|
+
- [`push()`](https://router.vuejs.org/api/interfaces/Router.html#push): Programmatically navigate to a new URL by pushing an entry in the history stack. **It is recommended to use [`navigateTo`](/docs/api/utils/navigate-to) instead.**
|
|
59
|
+
- [`replace()`](https://router.vuejs.org/api/interfaces/Router.html#replace): Programmatically navigate to a new URL by replacing the current entry in the routes history stack. **It is recommended to use [`navigateTo`](/docs/api/utils/navigate-to) instead.**
|
|
60
|
+
|
|
61
|
+
```ts [Example]
|
|
62
|
+
const router = useRouter()
|
|
63
|
+
|
|
64
|
+
router.back()
|
|
65
|
+
router.forward()
|
|
66
|
+
router.go(3)
|
|
67
|
+
router.push({ path: "/home" })
|
|
68
|
+
router.replace({ hash: "#bio" })
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/History" target="_blank"}
|
|
72
|
+
Read more about the browser's History API.
|
|
73
|
+
::
|
|
74
|
+
|
|
75
|
+
## Navigation Guards
|
|
76
|
+
|
|
77
|
+
`useRouter` composable provides `afterEach`, `beforeEach` and `beforeResolve` helper methods that acts as navigation guards.
|
|
78
|
+
|
|
79
|
+
However, Nuxt has a concept of **route middleware** that simplifies the implementation of navigation guards and provides a better developer experience.
|
|
80
|
+
|
|
81
|
+
:read-more{to="/docs/guide/directory-structure/middleware"}
|
|
82
|
+
|
|
83
|
+
## Promise and Error Handling
|
|
84
|
+
|
|
85
|
+
- [`isReady()`](https://router.vuejs.org/api/interfaces/Router.html#isReady): Returns a Promise that resolves when the router has completed the initial navigation.
|
|
86
|
+
- [`onError`](https://router.vuejs.org/api/interfaces/Router.html#onError): Adds an error handler that is called every time a non caught error happens during navigation.
|
|
87
|
+
|
|
88
|
+
:read-more{icon="i-simple-icons-vuedotjs" to="https://router.vuejs.org/api/interfaces/Router.html#Methods" title="Vue Router Docs" target="_blank"}
|
|
89
|
+
|
|
90
|
+
## Universal Router Instance
|
|
91
|
+
|
|
92
|
+
If you do not have a `pages/` folder, then [`useRouter`](/docs/api/composables/use-router) will return a universal router instance with similar helper methods, but be aware that not all features may be supported or behave in exactly the same way as with `vue-router`.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useRuntimeConfig'
|
|
3
|
+
description: 'Access runtime config variables with the useRuntimeConfig composable.'
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/nuxt.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```vue [app.vue]
|
|
14
|
+
<script setup lang="ts">
|
|
15
|
+
const config = useRuntimeConfig()
|
|
16
|
+
</script>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```ts [server/api/foo.ts]
|
|
20
|
+
export default defineEventHandler((event) => {
|
|
21
|
+
const config = useRuntimeConfig(event)
|
|
22
|
+
})
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
26
|
+
|
|
27
|
+
## Define Runtime Config
|
|
28
|
+
|
|
29
|
+
The example below shows how to set a public API base URL and a secret API token that is only accessible on the server.
|
|
30
|
+
|
|
31
|
+
We should always define `runtimeConfig` variables inside `nuxt.config`.
|
|
32
|
+
|
|
33
|
+
```ts [nuxt.config.ts]
|
|
34
|
+
export default defineNuxtConfig({
|
|
35
|
+
runtimeConfig: {
|
|
36
|
+
// Private keys are only available on the server
|
|
37
|
+
apiSecret: '123',
|
|
38
|
+
|
|
39
|
+
// Public keys that are exposed to the client
|
|
40
|
+
public: {
|
|
41
|
+
apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api'
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
::note
|
|
48
|
+
Variables that need to be accessible on the server are added directly inside `runtimeConfig`. Variables that need to be accessible on both the client and the server are defined in `runtimeConfig.public`.
|
|
49
|
+
::
|
|
50
|
+
|
|
51
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
52
|
+
|
|
53
|
+
## Access Runtime Config
|
|
54
|
+
|
|
55
|
+
To access runtime config, we can use `useRuntimeConfig()` composable:
|
|
56
|
+
|
|
57
|
+
```ts [server/api/test.ts]
|
|
58
|
+
export default defineEventHandler((event) => {
|
|
59
|
+
const config = useRuntimeConfig(event)
|
|
60
|
+
|
|
61
|
+
// Access public variables
|
|
62
|
+
const result = await $fetch(`/test`, {
|
|
63
|
+
baseURL: config.public.apiBase,
|
|
64
|
+
headers: {
|
|
65
|
+
// Access a private variable (only available on the server)
|
|
66
|
+
Authorization: `Bearer ${config.apiSecret}`
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
return result
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
In this example, since `apiBase` is defined within the `public` namespace, it is universally accessible on both server and client-side, while `apiSecret` **is only accessible on the server-side**.
|
|
74
|
+
|
|
75
|
+
## Environment Variables
|
|
76
|
+
|
|
77
|
+
It is possible to update runtime config values using a matching environment variable name prefixed with `NUXT_`.
|
|
78
|
+
|
|
79
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
80
|
+
|
|
81
|
+
### Using the `.env` File
|
|
82
|
+
|
|
83
|
+
We can set the environment variables inside the `.env` file to make them accessible during **development** and **build/generate**.
|
|
84
|
+
|
|
85
|
+
```ini [.env]
|
|
86
|
+
NUXT_PUBLIC_API_BASE = "https://api.localhost:5555"
|
|
87
|
+
NUXT_API_SECRET = "123"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
::note
|
|
91
|
+
Any environment variables set within `.env` file are accessed using `process.env` in the Nuxt app during **development** and **build/generate**.
|
|
92
|
+
::
|
|
93
|
+
|
|
94
|
+
::warning
|
|
95
|
+
In **production runtime**, you should use platform environment variables and `.env` is not used.
|
|
96
|
+
::
|
|
97
|
+
|
|
98
|
+
:read-more{to="/docs/guide/directory-structure/env"}
|
|
99
|
+
|
|
100
|
+
## `app` namespace
|
|
101
|
+
|
|
102
|
+
Nuxt uses `app` namespace in runtime-config with keys including `baseURL` and `cdnURL`. You can customize their values at runtime by setting environment variables.
|
|
103
|
+
|
|
104
|
+
::note
|
|
105
|
+
This is a reserved namespace. You should not introduce additional keys inside `app`.
|
|
106
|
+
::
|
|
107
|
+
|
|
108
|
+
### `app.baseURL`
|
|
109
|
+
|
|
110
|
+
By default, the `baseURL` is set to `'/'`.
|
|
111
|
+
|
|
112
|
+
However, the `baseURL` can be updated at runtime by setting the `NUXT_APP_BASE_URL` as an environment variable.
|
|
113
|
+
|
|
114
|
+
Then, you can access this new base URL using `config.app.baseURL`:
|
|
115
|
+
|
|
116
|
+
```ts [/plugins/my-plugin.ts]
|
|
117
|
+
export default defineNuxtPlugin((NuxtApp) => {
|
|
118
|
+
const config = useRuntimeConfig()
|
|
119
|
+
|
|
120
|
+
// Access baseURL universally
|
|
121
|
+
const baseURL = config.app.baseURL
|
|
122
|
+
})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `app.cdnURL`
|
|
126
|
+
|
|
127
|
+
This example shows how to set a custom CDN url and access them using `useRuntimeConfig()`.
|
|
128
|
+
|
|
129
|
+
You can use a custom CDN for serving static assets inside `.output/public` using the `NUXT_APP_CDN_URL` environment variable.
|
|
130
|
+
|
|
131
|
+
And then access the new CDN url using `config.app.cdnURL`.
|
|
132
|
+
|
|
133
|
+
```ts [server/api/foo.ts]
|
|
134
|
+
export default defineEventHandler((event) => {
|
|
135
|
+
const config = useRuntimeConfig(event)
|
|
136
|
+
|
|
137
|
+
// Access cdnURL universally
|
|
138
|
+
const cdnURL = config.app.cdnURL
|
|
139
|
+
})
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
:read-more{to="/docs/guide/going-further/runtime-config"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: useRuntimeHook
|
|
3
|
+
description: Registers a runtime hook in a Nuxt application and ensures it is properly disposed of when the scope is destroyed.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/runtime-hook.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
::important
|
|
12
|
+
This composable is available in Nuxt v3.14+.
|
|
13
|
+
::
|
|
14
|
+
|
|
15
|
+
```ts [signature]
|
|
16
|
+
function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(
|
|
17
|
+
name: THookName,
|
|
18
|
+
fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never
|
|
19
|
+
): void
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
### Parameters
|
|
25
|
+
|
|
26
|
+
- `name`: The name of the runtime hook to register. You can see the full list of [runtime Nuxt hooks here](/docs/api/advanced/hooks#app-hooks-runtime).
|
|
27
|
+
- `fn`: The callback function to execute when the hook is triggered. The function signature varies based on the hook name.
|
|
28
|
+
|
|
29
|
+
### Returns
|
|
30
|
+
|
|
31
|
+
The composable doesn't return a value, but it automatically unregisters the hook when the component's scope is destroyed.
|
|
32
|
+
|
|
33
|
+
## Example
|
|
34
|
+
|
|
35
|
+
```vue twoslash [pages/index.vue]
|
|
36
|
+
<script setup lang="ts">
|
|
37
|
+
// Register a hook that runs every time a link is prefetched, but which will be
|
|
38
|
+
// automatically cleaned up (and not called again) when the component is unmounted
|
|
39
|
+
useRuntimeHook('link:prefetch', (link) => {
|
|
40
|
+
console.log('Prefetching', link)
|
|
41
|
+
})
|
|
42
|
+
</script>
|
|
43
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useSeoMeta'
|
|
3
|
+
description: The useSeoMeta composable lets you define your site's SEO meta tags as a flat object with full TypeScript support.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/unjs/unhead/blob/main/packages/vue/src/composables.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
This helps you avoid common mistakes, such as using `name` instead of `property`, as well as typos - with over 100+ meta tags fully typed.
|
|
12
|
+
|
|
13
|
+
::important
|
|
14
|
+
This is the recommended way to add meta tags to your site as it is XSS safe and has full TypeScript support.
|
|
15
|
+
::
|
|
16
|
+
|
|
17
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```vue [app.vue]
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
useSeoMeta({
|
|
24
|
+
title: 'My Amazing Site',
|
|
25
|
+
ogTitle: 'My Amazing Site',
|
|
26
|
+
description: 'This is my amazing site, let me tell you all about it.',
|
|
27
|
+
ogDescription: 'This is my amazing site, let me tell you all about it.',
|
|
28
|
+
ogImage: 'https://example.com/image.png',
|
|
29
|
+
twitterCard: 'summary_large_image',
|
|
30
|
+
})
|
|
31
|
+
</script>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
When inserting tags that are reactive, you should use the computed getter syntax (`() => value`):
|
|
35
|
+
|
|
36
|
+
```vue [app.vue]
|
|
37
|
+
<script setup lang="ts">
|
|
38
|
+
const title = ref('My title')
|
|
39
|
+
|
|
40
|
+
useSeoMeta({
|
|
41
|
+
title,
|
|
42
|
+
description: () => `This is a description for the ${title.value} page`
|
|
43
|
+
})
|
|
44
|
+
</script>
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Parameters
|
|
48
|
+
|
|
49
|
+
There are over 100 parameters. See the [full list of parameters in the source code](https://github.com/harlan-zw/zhead/blob/main/packages/zhead/src/metaFlat.ts#L1035).
|
|
50
|
+
|
|
51
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
52
|
+
|
|
53
|
+
## Performance
|
|
54
|
+
|
|
55
|
+
In most instances, SEO meta tags don't need to be reactive as search engine robots primarily scan the initial page load.
|
|
56
|
+
|
|
57
|
+
For better performance, you can wrap your `useSeoMeta` calls in a server-only condition when the meta tags don't need to be reactive:
|
|
58
|
+
|
|
59
|
+
```vue [app.vue]
|
|
60
|
+
<script setup lang="ts">
|
|
61
|
+
if (import.meta.server) {
|
|
62
|
+
// These meta tags will only be added during server-side rendering
|
|
63
|
+
useSeoMeta({
|
|
64
|
+
robots: 'index, follow',
|
|
65
|
+
description: 'Static description that does not need reactivity',
|
|
66
|
+
ogImage: 'https://example.com/image.png',
|
|
67
|
+
// other static meta tags...
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const dynamicTitle = ref('My title')
|
|
72
|
+
// Only use reactive meta tags outside the condition when necessary
|
|
73
|
+
useSeoMeta({
|
|
74
|
+
title: () => dynamicTitle.value,
|
|
75
|
+
ogTitle: () => dynamicTitle.value,
|
|
76
|
+
})
|
|
77
|
+
</script>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
This previously used the [`useServerSeoMeta`](/docs/api/composables/use-server-seo-meta) composable, but it has been deprecated in favor of this approach.
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 'useServerSeoMeta'
|
|
3
|
+
description: The useServerSeoMeta composable lets you define your site's SEO meta tags as a flat object with full TypeScript support.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/unjs/unhead/blob/main/packages/vue/src/composables.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
Just like [`useSeoMeta`](/docs/api/composables/use-seo-meta), `useServerSeoMeta` composable lets you define your site's SEO meta tags as a flat object with full TypeScript support.
|
|
12
|
+
|
|
13
|
+
:read-more{to="/docs/api/composables/use-seo-meta"}
|
|
14
|
+
|
|
15
|
+
In most instances, the meta doesn't need to be reactive as robots will only scan the initial load. So we recommend using [`useServerSeoMeta`](/docs/api/composables/use-server-seo-meta) as a performance-focused utility that will not do anything (or return a `head` object) on the client.
|
|
16
|
+
|
|
17
|
+
```vue [app.vue]
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
useServerSeoMeta({
|
|
20
|
+
robots: 'index, follow'
|
|
21
|
+
})
|
|
22
|
+
</script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Parameters are exactly the same as with [`useSeoMeta`](/docs/api/composables/use-seo-meta)
|
|
26
|
+
|
|
27
|
+
:read-more{to="/docs/getting-started/seo-meta"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "useState"
|
|
3
|
+
description: The useState composable creates a reactive and SSR-friendly shared state.
|
|
4
|
+
links:
|
|
5
|
+
- label: Source
|
|
6
|
+
icon: i-simple-icons-github
|
|
7
|
+
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/state.ts
|
|
8
|
+
size: xs
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Create a reactive state and set default value
|
|
15
|
+
const count = useState('counter', () => Math.round(Math.random() * 100))
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
:read-more{to="/docs/getting-started/state-management"}
|
|
19
|
+
|
|
20
|
+
::important
|
|
21
|
+
Because the data inside `useState` will be serialized to JSON, it is important that it does not contain anything that cannot be serialized, such as classes, functions or symbols.
|
|
22
|
+
::
|
|
23
|
+
|
|
24
|
+
::warning
|
|
25
|
+
`useState` is a reserved function name transformed by the compiler, so you should not name your own function `useState`.
|
|
26
|
+
::
|
|
27
|
+
|
|
28
|
+
:video-accordion{title="Watch a video from Alexander Lichter about why and when to use useState" videoId="mv0WcBABcIk"}
|
|
29
|
+
|
|
30
|
+
## Using `shallowRef`
|
|
31
|
+
|
|
32
|
+
If you don't need your state to be deeply reactive, you can combine `useState` with [`shallowRef`](https://vuejs.org/api/reactivity-advanced.html#shallowref). This can improve performance when your state contains large objects and arrays.
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
const state = useState('my-shallow-state', () => shallowRef({ deep: 'not reactive' }))
|
|
36
|
+
// isShallow(state) === true
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Type
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
useState<T>(init?: () => T | Ref<T>): Ref<T>
|
|
43
|
+
useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
- `key`: A unique key ensuring that data fetching is properly de-duplicated across requests. If you do not provide a key, then a key that is unique to the file and line number of the instance of [`useState`](/docs/api/composables/use-state) will be generated for you.
|
|
47
|
+
- `init`: A function that provides initial value for the state when not initiated. This function can also return a `Ref`.
|
|
48
|
+
- `T`: (typescript only) Specify the type of state
|