@nuxt/docs-nightly 4.1.3-29314777.50febbbb → 4.1.3-29316225.304409da

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/1.getting-started/03.configuration.md +19 -19
  2. package/1.getting-started/04.views.md +1 -1
  3. package/1.getting-started/05.assets.md +8 -2
  4. package/1.getting-started/06.styling.md +50 -40
  5. package/1.getting-started/07.routing.md +4 -4
  6. package/1.getting-started/08.seo-meta.md +46 -33
  7. package/1.getting-started/09.transitions.md +38 -33
  8. package/1.getting-started/10.data-fetching.md +47 -39
  9. package/1.getting-started/11.state-management.md +15 -8
  10. package/1.getting-started/12.error-handling.md +6 -4
  11. package/1.getting-started/13.server.md +3 -3
  12. package/1.getting-started/14.layers.md +18 -12
  13. package/1.getting-started/15.prerendering.md +24 -24
  14. package/1.getting-started/16.deployment.md +7 -7
  15. package/1.getting-started/17.testing.md +41 -41
  16. package/1.getting-started/18.upgrade.md +48 -66
  17. package/2.guide/1.directory-structure/1.app/1.components.md +36 -19
  18. package/2.guide/1.directory-structure/1.app/1.composables.md +7 -7
  19. package/2.guide/1.directory-structure/1.app/1.layouts.md +9 -5
  20. package/2.guide/1.directory-structure/1.app/1.middleware.md +20 -14
  21. package/2.guide/1.directory-structure/1.app/1.pages.md +19 -17
  22. package/2.guide/1.directory-structure/1.app/1.plugins.md +17 -17
  23. package/2.guide/1.directory-structure/1.app/1.utils.md +1 -1
  24. package/2.guide/1.directory-structure/1.app/3.app-config.md +6 -6
  25. package/2.guide/1.directory-structure/1.app/3.error.md +4 -4
  26. package/2.guide/1.directory-structure/1.content.md +4 -1
  27. package/2.guide/1.directory-structure/1.modules.md +4 -4
  28. package/2.guide/1.directory-structure/1.public.md +1 -1
  29. package/2.guide/1.directory-structure/1.server.md +28 -28
  30. package/2.guide/1.directory-structure/1.shared.md +1 -1
  31. package/2.guide/2.concepts/1.auto-imports.md +11 -11
  32. package/2.guide/2.concepts/2.vuejs-development.md +5 -5
  33. package/2.guide/2.concepts/3.rendering.md +14 -12
  34. package/2.guide/2.concepts/5.modules.md +2 -2
  35. package/2.guide/2.concepts/7.esm.md +14 -12
  36. package/2.guide/2.concepts/8.typescript.md +4 -4
  37. package/2.guide/3.going-further/1.events.md +2 -2
  38. package/2.guide/3.going-further/1.experimental-features.md +234 -73
  39. package/2.guide/3.going-further/1.features.md +44 -9
  40. package/2.guide/3.going-further/1.internals.md +15 -15
  41. package/2.guide/3.going-further/10.runtime-config.md +7 -7
  42. package/2.guide/3.going-further/2.hooks.md +8 -8
  43. package/2.guide/3.going-further/3.modules.md +76 -74
  44. package/2.guide/3.going-further/4.kit.md +3 -3
  45. package/2.guide/3.going-further/6.nuxt-app.md +1 -1
  46. package/2.guide/3.going-further/7.layers.md +50 -41
  47. package/2.guide/3.going-further/9.debugging.md +2 -2
  48. package/2.guide/4.recipes/1.custom-routing.md +19 -19
  49. package/2.guide/4.recipes/2.vite-plugin.md +3 -3
  50. package/2.guide/4.recipes/3.custom-usefetch.md +9 -9
  51. package/2.guide/4.recipes/4.sessions-and-authentication.md +33 -19
  52. package/2.guide/5.best-practices/performance.md +8 -8
  53. package/3.api/1.components/1.client-only.md +6 -3
  54. package/3.api/1.components/1.nuxt-client-fallback.md +9 -6
  55. package/3.api/1.components/11.teleports.md +4 -1
  56. package/3.api/1.components/12.nuxt-route-announcer.md +7 -7
  57. package/3.api/1.components/13.nuxt-time.md +44 -17
  58. package/3.api/1.components/2.nuxt-page.md +2 -2
  59. package/3.api/1.components/3.nuxt-layout.md +9 -4
  60. package/3.api/1.components/4.nuxt-link.md +38 -18
  61. package/3.api/1.components/6.nuxt-error-boundary.md +11 -9
  62. package/3.api/2.composables/on-prehydrate.md +2 -2
  63. package/3.api/2.composables/use-async-data.md +11 -11
  64. package/3.api/2.composables/use-cookie.md +26 -18
  65. package/3.api/2.composables/use-error.md +1 -1
  66. package/3.api/2.composables/use-fetch.md +13 -13
  67. package/3.api/2.composables/use-head-safe.md +5 -5
  68. package/3.api/2.composables/use-head.md +2 -2
  69. package/3.api/2.composables/use-hydration.md +5 -5
  70. package/3.api/2.composables/use-loading-indicator.md +10 -10
  71. package/3.api/2.composables/use-nuxt-app.md +9 -9
  72. package/3.api/2.composables/use-nuxt-data.md +7 -7
  73. package/3.api/2.composables/use-preview-mode.md +12 -15
  74. package/3.api/2.composables/use-request-fetch.md +1 -1
  75. package/3.api/2.composables/use-request-headers.md +3 -3
  76. package/3.api/2.composables/use-response-header.md +7 -8
  77. package/3.api/2.composables/use-route-announcer.md +3 -3
  78. package/3.api/2.composables/use-router.md +5 -3
  79. package/3.api/2.composables/use-runtime-config.md +6 -6
  80. package/3.api/2.composables/use-runtime-hook.md +1 -1
  81. package/3.api/2.composables/use-seo-meta.md +1 -1
  82. package/3.api/2.composables/use-server-seo-meta.md +1 -1
  83. package/3.api/2.composables/use-state.md +3 -3
  84. package/3.api/3.utils/$fetch.md +5 -3
  85. package/3.api/3.utils/abort-navigation.md +2 -2
  86. package/3.api/3.utils/add-route-middleware.md +3 -3
  87. package/3.api/3.utils/call-once.md +3 -3
  88. package/3.api/3.utils/clear-error.md +1 -1
  89. package/3.api/3.utils/clear-nuxt-data.md +2 -2
  90. package/3.api/3.utils/clear-nuxt-state.md +2 -2
  91. package/3.api/3.utils/create-error.md +1 -1
  92. package/3.api/3.utils/define-lazy-hydration-component.md +13 -13
  93. package/3.api/3.utils/define-nuxt-component.md +5 -5
  94. package/3.api/3.utils/define-nuxt-plugin.md +11 -11
  95. package/3.api/3.utils/define-nuxt-route-middleware.md +2 -2
  96. package/3.api/3.utils/define-page-meta.md +14 -14
  97. package/3.api/3.utils/define-route-rules.md +3 -3
  98. package/3.api/3.utils/navigate-to.md +9 -9
  99. package/3.api/3.utils/preload-components.md +1 -1
  100. package/3.api/3.utils/prerender-routes.md +2 -2
  101. package/3.api/3.utils/refresh-cookie.md +3 -3
  102. package/3.api/3.utils/refresh-nuxt-data.md +9 -4
  103. package/3.api/3.utils/reload-nuxt-app.md +2 -2
  104. package/3.api/3.utils/set-response-status.md +1 -1
  105. package/3.api/3.utils/show-error.md +2 -2
  106. package/3.api/3.utils/update-app-config.md +2 -1
  107. package/3.api/4.commands/prepare.md +4 -0
  108. package/3.api/5.kit/1.modules.md +36 -36
  109. package/3.api/5.kit/10.templates.md +8 -6
  110. package/3.api/5.kit/11.nitro.md +62 -62
  111. package/3.api/5.kit/12.resolving.md +2 -2
  112. package/3.api/5.kit/14.builder.md +1 -0
  113. package/3.api/5.kit/15.examples.md +2 -2
  114. package/3.api/5.kit/16.layers.md +26 -26
  115. package/3.api/5.kit/3.compatibility.md +12 -12
  116. package/3.api/5.kit/4.autoimports.md +12 -12
  117. package/3.api/5.kit/5.components.md +5 -5
  118. package/3.api/5.kit/6.context.md +3 -3
  119. package/3.api/5.kit/7.pages.md +4 -4
  120. package/3.api/5.kit/8.layout.md +1 -1
  121. package/3.api/5.kit/9.plugins.md +5 -4
  122. package/3.api/6.advanced/2.import-meta.md +3 -3
  123. package/3.api/6.nuxt-config.md +293 -858
  124. package/6.bridge/1.overview.md +1 -1
  125. package/6.bridge/10.configuration.md +2 -1
  126. package/6.bridge/2.typescript.md +2 -2
  127. package/6.bridge/3.bridge-composition-api.md +2 -2
  128. package/6.bridge/4.plugins-and-middleware.md +5 -5
  129. package/6.bridge/5.nuxt3-compatible-api.md +11 -8
  130. package/6.bridge/6.meta.md +15 -14
  131. package/6.bridge/8.nitro.md +2 -2
  132. package/6.bridge/9.vite.md +3 -3
  133. package/7.migration/2.configuration.md +17 -15
  134. package/7.migration/4.meta.md +17 -14
  135. package/7.migration/5.plugins-and-middleware.md +5 -5
  136. package/7.migration/6.pages-and-layouts.md +15 -11
  137. package/7.migration/7.component-options.md +3 -3
  138. package/7.migration/8.runtime-config.md +3 -3
  139. package/package.json +1 -1
@@ -58,20 +58,20 @@ Used by `finish()`. Clear all timers and intervals used by the composable.
58
58
 
59
59
  ```vue
60
60
  <script setup lang="ts">
61
- const { progress, isLoading, start, finish, clear } = useLoadingIndicator({
62
- duration: 2000,
63
- throttle: 200,
64
- // This is how progress is calculated by default
65
- estimatedProgress: (duration, elapsed) => (2 / Math.PI * 100) * Math.atan(elapsed / duration * 100 / 50)
66
- })
61
+ const { progress, isLoading, start, finish, clear } = useLoadingIndicator({
62
+ duration: 2000,
63
+ throttle: 200,
64
+ // This is how progress is calculated by default
65
+ estimatedProgress: (duration, elapsed) => (2 / Math.PI * 100) * Math.atan(elapsed / duration * 100 / 50),
66
+ })
67
67
  </script>
68
68
  ```
69
69
 
70
70
  ```vue
71
71
  <script setup lang="ts">
72
- const { start, set } = useLoadingIndicator()
73
- // same as set(0, { force: true })
74
- // set the progress to 0, and show loading immediately
75
- start({ force: true })
72
+ const { start, set } = useLoadingIndicator()
73
+ // same as set(0, { force: true })
74
+ // set the progress to 0, and show loading immediately
75
+ start({ force: true })
76
76
  </script>
77
77
  ```
@@ -34,9 +34,9 @@ By default, the shared runtime context of Nuxt is namespaced under the [`buildId
34
34
 
35
35
  `provide` function accepts `name` and `value` parameters.
36
36
 
37
- ```js
37
+ ```ts
38
38
  const nuxtApp = useNuxtApp()
39
- nuxtApp.provide('hello', (name) => `Hello ${name}!`)
39
+ nuxtApp.provide('hello', name => `Hello ${name}!`)
40
40
 
41
41
  // Prints "Hello name!"
42
42
  console.log(nuxtApp.$hello('name'))
@@ -112,7 +112,7 @@ Nuxt exposes the following properties through `ssrContext`:
112
112
  </script>
113
113
  ```
114
114
  ```ts [server/api/count.ts]
115
- export default defineEventHandler(event => {
115
+ export default defineEventHandler((event) => {
116
116
  return { count: 1 }
117
117
  })
118
118
  ```
@@ -173,7 +173,7 @@ export default defineComponent({
173
173
  // ...
174
174
  }
175
175
  })
176
- }
176
+ },
177
177
  })
178
178
  ```
179
179
 
@@ -204,7 +204,7 @@ export default defineNuxtRouteMiddleware(async (to, from) => {
204
204
 
205
205
  #### Usage
206
206
 
207
- ```js
207
+ ```ts
208
208
  const result = nuxtApp.runWithContext(() => functionWithContext())
209
209
  ```
210
210
 
@@ -218,14 +218,14 @@ Vue.js Composition API (and Nuxt composables similarly) work by depending on an
218
218
 
219
219
  What it does mean? The Composition API and Nuxt Composables are only available during lifecycle and in same tick before any async operation:
220
220
 
221
- ```js
221
+ ```ts
222
222
  // --- Vue internal ---
223
223
  const _vueInstance = null
224
224
  const getCurrentInstance = () => _vueInstance
225
225
  // ---
226
226
 
227
227
  // Vue / Nuxt sets a global variable referencing to current component in _vueInstance when calling setup()
228
- async function setup() {
228
+ async function setup () {
229
229
  getCurrentInstance() // Works
230
230
  await someAsyncOperation() // Vue unsets the context in same tick before async operation!
231
231
  getCurrentInstance() // null
@@ -236,7 +236,7 @@ The classic solution to this, is caching the current instance on first call to a
236
236
 
237
237
  To overcome this limitation, Vue does some behind the scenes work when compiling our application code and restores context after each call for `<script setup>`:
238
238
 
239
- ```js
239
+ ```ts
240
240
  const __instance = getCurrentInstance() // Generated by Vue compiler
241
241
  getCurrentInstance() // Works!
242
242
  await someAsyncOperation() // Vue unsets the context
@@ -279,7 +279,7 @@ You can use it for composables that do not require `nuxtApp`, or to simply check
279
279
  Example usage:
280
280
 
281
281
  ```ts [composable.ts]
282
- export function useStandType() {
282
+ export function useStandType () {
283
283
  // Always works on the client
284
284
  if (tryUseNuxtApp()) {
285
285
  return useRuntimeConfig().public.STAND_TYPE
@@ -50,10 +50,10 @@ const route = useRoute()
50
50
 
51
51
  const { data } = useLazyFetch(`/api/posts/${route.params.id}`, {
52
52
  key: `post-${route.params.id}`,
53
- default() {
53
+ default () {
54
54
  // Find the individual post from the cache and set it as the default value.
55
55
  return posts.value.find(post => post.id === route.params.id)
56
- }
56
+ },
57
57
  })
58
58
  </script>
59
59
  ```
@@ -80,10 +80,10 @@ let previousTodos = []
80
80
  const { data: todos } = useNuxtData('todos')
81
81
 
82
82
  async function addTodo () {
83
- return $fetch('/api/addTodo', {
83
+ await $fetch('/api/addTodo', {
84
84
  method: 'post',
85
85
  body: {
86
- todo: newTodo.value
86
+ todo: newTodo.value,
87
87
  },
88
88
  onRequest () {
89
89
  // Store the previously cached value to restore if fetch fails.
@@ -99,7 +99,7 @@ async function addTodo () {
99
99
  async onResponse () {
100
100
  // Invalidate todos in the background if the request succeeded.
101
101
  await refreshNuxtData('todos')
102
- }
102
+ },
103
103
  })
104
104
  }
105
105
  </script>
@@ -107,6 +107,6 @@ async function addTodo () {
107
107
 
108
108
  ## Type
109
109
 
110
- ```ts
111
- useNuxtData<DataT = any> (key: string): { data: Ref<DataT | undefined> }
110
+ ```ts [Signature]
111
+ export function useNuxtData<DataT = any> (key: string): { data: Ref<DataT | undefined> }
112
112
  ```
@@ -14,7 +14,7 @@ Preview mode allows you to see how your changes would be displayed on a live sit
14
14
 
15
15
  You can use the built-in `usePreviewMode` composable to access and control preview state in Nuxt. If the composable detects preview mode it will automatically force any updates necessary for [`useAsyncData`](/docs/4.x/api/composables/use-async-data) and [`useFetch`](/docs/4.x/api/composables/use-fetch) to rerender preview content.
16
16
 
17
- ```js
17
+ ```ts
18
18
  const { enabled, state } = usePreviewMode()
19
19
  ```
20
20
 
@@ -24,13 +24,14 @@ const { enabled, state } = usePreviewMode()
24
24
 
25
25
  You can specify a custom way to enable preview mode. By default the `usePreviewMode` composable will enable preview mode if there is a `preview` param in url that is equal to `true` (for example, `http://localhost:3000?preview=true`). You can wrap the `usePreviewMode` into custom composable, to keep options consistent across usages and prevent any errors.
26
26
 
27
- ```js
27
+ ```ts
28
28
  export function useMyPreviewMode () {
29
+ const route = useRoute()
29
30
  return usePreviewMode({
30
31
  shouldEnable: () => {
31
32
  return !!route.query.customPreview
32
- }
33
- });
33
+ },
34
+ })
34
35
  }
35
36
  ```
36
37
 
@@ -38,13 +39,13 @@ export function useMyPreviewMode () {
38
39
 
39
40
  `usePreviewMode` will try to store the value of a `token` param from url in state. You can modify this state and it will be available for all [`usePreviewMode`](/docs/4.x/api/composables/use-preview-mode) calls.
40
41
 
41
- ```js
42
+ ```ts
42
43
  const data1 = ref('data1')
43
44
 
44
45
  const { enabled, state } = usePreviewMode({
45
46
  getState: (currentState) => {
46
47
  return { data1, data2: 'data2' }
47
- }
48
+ },
48
49
  })
49
50
  ```
50
51
 
@@ -60,14 +61,14 @@ When preview mode is disabled, the composable will attach a callback to call `re
60
61
 
61
62
  You can specify custom callbacks to be triggered by providing your own functions for the `onEnable` and `onDisable` options.
62
63
 
63
- ```js
64
+ ```ts
64
65
  const { enabled, state } = usePreviewMode({
65
66
  onEnable: () => {
66
67
  console.log('preview mode has been enabled')
67
68
  },
68
69
  onDisable: () => {
69
70
  console.log('preview mode has been disabled')
70
- }
71
+ },
71
72
  })
72
73
  ```
73
74
 
@@ -81,8 +82,8 @@ const { enabled, state } = usePreviewMode()
81
82
 
82
83
  const { data } = await useFetch('/api/preview', {
83
84
  query: {
84
- apiKey: state.token
85
- }
85
+ apiKey: state.token,
86
+ },
86
87
  })
87
88
  </script>
88
89
 
@@ -107,11 +108,7 @@ npx nuxt generate
107
108
  npx nuxt preview
108
109
  ```
109
110
 
110
- Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once:
111
-
112
- ```js
113
- ?preview=true
114
- ```
111
+ Then you can see your preview page by adding the query param `preview` to the end of the page you want to see once, for example `http://localhost:3000/?preview=true`.
115
112
 
116
113
  ::note
117
114
  `usePreviewMode` should be tested locally with `nuxt generate` and then `nuxt preview` rather than `nuxt dev`. (The [preview command](/docs/4.x/api/commands/preview) is not related to preview mode.)
@@ -33,7 +33,7 @@ const { data: forwarded } = await useAsyncData(() => requestFetch('/api/cookies'
33
33
 
34
34
  // This will NOT forward anything
35
35
  // Result: { cookies: {} }
36
- const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
36
+ const { data: notForwarded } = await useAsyncData(() => $fetch('/api/cookies'))
37
37
  </script>
38
38
  ```
39
39
 
@@ -10,12 +10,12 @@ links:
10
10
 
11
11
  You can use built-in [`useRequestHeaders`](/docs/4.x/api/composables/use-request-headers) composable to access the incoming request headers within your pages, components, and plugins.
12
12
 
13
- ```js
13
+ ```ts
14
14
  // Get all request headers
15
15
  const headers = useRequestHeaders()
16
16
 
17
17
  // Get only cookie request header
18
- const headers = useRequestHeaders(['cookie'])
18
+ const { cookie } = useRequestHeaders(['cookie'])
19
19
  ```
20
20
 
21
21
  ::tip
@@ -31,7 +31,7 @@ The example below adds the `authorization` request header to an isomorphic `$fet
31
31
  ```vue [app/pages/some-page.vue]
32
32
  <script setup lang="ts">
33
33
  const { data } = await useFetch('/api/confidential', {
34
- headers: useRequestHeaders(['authorization'])
34
+ headers: useRequestHeaders(['authorization']),
35
35
  })
36
36
  </script>
37
37
  ```
@@ -16,8 +16,8 @@ You can use the built-in [`useResponseHeader`](/docs/4.x/api/composables/use-res
16
16
 
17
17
  ```ts
18
18
  // Set a custom response header
19
- const header = useResponseHeader('X-My-Header');
20
- header.value = 'my-value';
19
+ const header = useResponseHeader('X-My-Header')
20
+ header.value = 'my-value'
21
21
  ```
22
22
 
23
23
  ## Example
@@ -27,8 +27,8 @@ We can use `useResponseHeader` to easily set a response header on a per-page bas
27
27
  ```vue [app/pages/test.vue]
28
28
  <script setup>
29
29
  // pages/test.vue
30
- const header = useResponseHeader('X-My-Header');
31
- header.value = 'my-value';
30
+ const header = useResponseHeader('X-My-Header')
31
+ header.value = 'my-value'
32
32
  </script>
33
33
 
34
34
  <template>
@@ -41,8 +41,7 @@ We can use `useResponseHeader` for example in Nuxt [middleware](/docs/4.x/guide/
41
41
 
42
42
  ```ts [app/middleware/my-header-middleware.ts]
43
43
  export default defineNuxtRouteMiddleware((to, from) => {
44
- const header = useResponseHeader('X-My-Always-Header');
45
- header.value = `I'm Always here!`;
46
- });
47
-
44
+ const header = useResponseHeader('X-My-Always-Header')
45
+ header.value = `I'm Always here!`
46
+ })
48
47
  ```
@@ -53,8 +53,8 @@ Sets the message with `politeness = "assertive"`
53
53
 
54
54
  ```vue [app/pages/index.vue]
55
55
  <script setup lang="ts">
56
- const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
57
- politeness: 'assertive'
58
- })
56
+ const { message, politeness, set, polite, assertive } = useRouteAnnouncer({
57
+ politeness: 'assertive',
58
+ })
59
59
  </script>
60
60
  ```
@@ -18,7 +18,9 @@ If you only need the router instance within your template, use `$router`:
18
18
 
19
19
  ```vue [app/pages/index.vue]
20
20
  <template>
21
- <button @click="$router.back()">Back</button>
21
+ <button @click="$router.back()">
22
+ Back
23
+ </button>
22
24
  </template>
23
25
  ```
24
26
 
@@ -64,8 +66,8 @@ const router = useRouter()
64
66
  router.back()
65
67
  router.forward()
66
68
  router.go(3)
67
- router.push({ path: "/home" })
68
- router.replace({ hash: "#bio" })
69
+ router.push({ path: '/home' })
70
+ router.replace({ hash: '#bio' })
69
71
  ```
70
72
 
71
73
  ::read-more{icon="i-simple-icons-mdnwebdocs" to="https://developer.mozilla.org/en-US/docs/Web/API/History" target="_blank"}
@@ -38,9 +38,9 @@ export default defineNuxtConfig({
38
38
 
39
39
  // Public keys that are exposed to the client
40
40
  public: {
41
- apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api'
42
- }
43
- }
41
+ apiBase: process.env.NUXT_PUBLIC_API_BASE || '/api',
42
+ },
43
+ },
44
44
  })
45
45
  ```
46
46
 
@@ -63,11 +63,11 @@ export default defineEventHandler(async (event) => {
63
63
  baseURL: config.public.apiBase,
64
64
  headers: {
65
65
  // Access a private variable (only available on the server)
66
- Authorization: `Bearer ${config.apiSecret}`
67
- }
66
+ Authorization: `Bearer ${config.apiSecret}`,
67
+ },
68
68
  })
69
69
  return result
70
- }
70
+ })
71
71
  ```
72
72
 
73
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**.
@@ -13,7 +13,7 @@ This composable is available in Nuxt v3.14+.
13
13
  ::
14
14
 
15
15
  ```ts [signature]
16
- function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks>(
16
+ function useRuntimeHook<THookName extends keyof RuntimeNuxtHooks> (
17
17
  name: THookName,
18
18
  fn: RuntimeNuxtHooks[THookName] extends HookCallback ? RuntimeNuxtHooks[THookName] : never
19
19
  ): void
@@ -39,7 +39,7 @@ const title = ref('My title')
39
39
 
40
40
  useSeoMeta({
41
41
  title,
42
- description: () => `This is a description for the ${title.value} page`
42
+ description: () => `This is a description for the ${title.value} page`,
43
43
  })
44
44
  </script>
45
45
  ```
@@ -17,7 +17,7 @@ In most instances, the meta doesn't need to be reactive as robots will only scan
17
17
  ```vue [app/app.vue]
18
18
  <script setup lang="ts">
19
19
  useServerSeoMeta({
20
- robots: 'index, follow'
20
+ robots: 'index, follow',
21
21
  })
22
22
  </script>
23
23
  ```
@@ -38,9 +38,9 @@ const state = useState('my-shallow-state', () => shallowRef({ deep: 'not reactiv
38
38
 
39
39
  ## Type
40
40
 
41
- ```ts
42
- useState<T>(init?: () => T | Ref<T>): Ref<T>
43
- useState<T>(key: string, init?: () => T | Ref<T>): Ref<T>
41
+ ```ts [Signature]
42
+ export function useState<T> (init?: () => T | Ref<T>): Ref<T>
43
+ export function useState<T> (key: string, init?: () => T | Ref<T>): Ref<T>
44
44
  ```
45
45
 
46
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/4.x/api/composables/use-state) will be generated for you.
@@ -41,16 +41,18 @@ You can use `$fetch` in any methods that are executed only on client-side.
41
41
 
42
42
  ```vue [app/pages/contact.vue]
43
43
  <script setup lang="ts">
44
- async function contactForm() {
44
+ async function contactForm () {
45
45
  await $fetch('/api/contact', {
46
46
  method: 'POST',
47
- body: { hello: 'world '}
47
+ body: { hello: 'world' },
48
48
  })
49
49
  }
50
50
  </script>
51
51
 
52
52
  <template>
53
- <button @click="contactForm">Contact</button>
53
+ <button @click="contactForm">
54
+ Contact
55
+ </button>
54
56
  </template>
55
57
  ```
56
58
 
@@ -14,8 +14,8 @@ links:
14
14
 
15
15
  ## Type
16
16
 
17
- ```ts
18
- abortNavigation(err?: Error | string): false
17
+ ```ts [Signature]
18
+ export function abortNavigation (err?: Error | string): false
19
19
  ```
20
20
 
21
21
  ## Parameters
@@ -80,9 +80,9 @@ Global route middleware can be defined in two ways:
80
80
  ```ts [app/plugins/my-plugin.ts]
81
81
  export default defineNuxtPlugin(() => {
82
82
  addRouteMiddleware('global-middleware', (to, from) => {
83
- console.log('global middleware that runs on every route change')
84
- },
85
- { global: true }
83
+ console.log('global middleware that runs on every route change')
84
+ },
85
+ { global: true },
86
86
  )
87
87
  })
88
88
  ```
@@ -70,9 +70,9 @@ Note that `callOnce` doesn't return anything. You should use [`useAsyncData`](/d
70
70
 
71
71
  ## Type
72
72
 
73
- ```ts
74
- callOnce (key?: string, fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
75
- callOnce(fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
73
+ ```ts [Signature]
74
+ export function callOnce (key?: string, fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
75
+ export function callOnce (fn?: (() => any | Promise<any>), options?: CallOnceOptions): Promise<void>
76
76
 
77
77
  type CallOnceOptions = {
78
78
  /**
@@ -16,7 +16,7 @@ Within your pages, components, and plugins, you can use `clearError` to clear al
16
16
 
17
17
  You can provide an optional path to redirect to (for example, if you want to navigate to a 'safe' page).
18
18
 
19
- ```js
19
+ ```ts
20
20
  // Without redirect
21
21
  clearError()
22
22
 
@@ -14,8 +14,8 @@ This method is useful if you want to invalidate the data fetching for another pa
14
14
 
15
15
  ## Type
16
16
 
17
- ```ts
18
- clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void
17
+ ```ts [Signature]
18
+ export function clearNuxtData (keys?: string | string[] | ((key: string) => boolean)): void
19
19
  ```
20
20
 
21
21
  ## Parameters
@@ -14,8 +14,8 @@ This method is useful if you want to invalidate the state of `useState`.
14
14
 
15
15
  ## Type
16
16
 
17
- ```ts
18
- clearNuxtState (keys?: string | string[] | ((key: string) => boolean)): void
17
+ ```ts [Signature]
18
+ export function clearNuxtState (keys?: string | string[] | ((key: string) => boolean)): void
19
19
  ```
20
20
 
21
21
  ## Parameters
@@ -45,7 +45,7 @@ Use `createError` to trigger error handling in server API routes.
45
45
  export default eventHandler(() => {
46
46
  throw createError({
47
47
  statusCode: 404,
48
- statusMessage: 'Page Not Found'
48
+ statusMessage: 'Page Not Found',
49
49
  })
50
50
  })
51
51
  ```
@@ -20,13 +20,13 @@ Hydrates the component when it becomes visible in the viewport.
20
20
  <script setup lang="ts">
21
21
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
22
22
  'visible',
23
- () => import('./components/MyComponent.vue')
23
+ () => import('./components/MyComponent.vue'),
24
24
  )
25
25
  </script>
26
26
 
27
27
  <template>
28
28
  <div>
29
- <!--
29
+ <!--
30
30
  Hydration will be triggered when
31
31
  the element(s) is 100px away from entering the viewport.
32
32
  -->
@@ -53,7 +53,7 @@ Hydrates the component when the browser is idle. This is suitable if you need th
53
53
  <script setup lang="ts">
54
54
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
55
55
  'idle',
56
- () => import('./components/MyComponent.vue')
56
+ () => import('./components/MyComponent.vue'),
57
57
  )
58
58
  </script>
59
59
 
@@ -81,7 +81,7 @@ Hydrates the component after a specified interaction (e.g., click, mouseover).
81
81
  <script setup lang="ts">
82
82
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
83
83
  'interaction',
84
- () => import('./components/MyComponent.vue')
84
+ () => import('./components/MyComponent.vue'),
85
85
  )
86
86
  </script>
87
87
 
@@ -110,7 +110,7 @@ Hydrates the component when the window matches a media query.
110
110
  <script setup lang="ts">
111
111
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
112
112
  'mediaQuery',
113
- () => import('./components/MyComponent.vue')
113
+ () => import('./components/MyComponent.vue'),
114
114
  )
115
115
  </script>
116
116
 
@@ -136,8 +136,8 @@ Hydrates the component after a specified delay (in milliseconds).
136
136
  ```vue
137
137
  <script setup lang="ts">
138
138
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
139
- 'time',
140
- () => import('./components/MyComponent.vue')
139
+ 'time',
140
+ () => import('./components/MyComponent.vue'),
141
141
  )
142
142
  </script>
143
143
 
@@ -159,12 +159,12 @@ Hydrates the component based on a boolean condition.
159
159
  <script setup lang="ts">
160
160
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
161
161
  'if',
162
- () => import('./components/MyComponent.vue')
162
+ () => import('./components/MyComponent.vue'),
163
163
  )
164
164
 
165
165
  const isReady = ref(false)
166
166
 
167
- function myFunction() {
167
+ function myFunction () {
168
168
  // Trigger custom hydration strategy...
169
169
  isReady.value = true
170
170
  }
@@ -188,7 +188,7 @@ Never hydrates the component.
188
188
  <script setup lang="ts">
189
189
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
190
190
  'never',
191
- () => import('./components/MyComponent.vue')
191
+ () => import('./components/MyComponent.vue'),
192
192
  )
193
193
  </script>
194
194
 
@@ -208,11 +208,11 @@ All delayed hydration components emit a `@hydrated` event when they are hydrated
208
208
  <script setup lang="ts">
209
209
  const LazyHydrationMyComponent = defineLazyHydrationComponent(
210
210
  'visible',
211
- () => import('./components/MyComponent.vue')
211
+ () => import('./components/MyComponent.vue'),
212
212
  )
213
213
 
214
- function onHydrate() {
215
- console.log("Component has been hydrated!")
214
+ function onHydrate () {
215
+ console.log('Component has been hydrated!')
216
216
  }
217
217
  </script>
218
218
 
@@ -25,11 +25,11 @@ If you choose not to use `setup()` in your app, you can use the `asyncData()` me
25
25
  ```vue [app/pages/index.vue]
26
26
  <script lang="ts">
27
27
  export default defineNuxtComponent({
28
- async asyncData() {
28
+ asyncData () {
29
29
  return {
30
30
  data: {
31
- greetings: 'hello world!'
32
- }
31
+ greetings: 'hello world!',
32
+ },
33
33
  }
34
34
  },
35
35
  })
@@ -43,9 +43,9 @@ If you choose not to use `setup()` in your app, you can use the `head()` method
43
43
  ```vue [app/pages/index.vue]
44
44
  <script lang="ts">
45
45
  export default defineNuxtComponent({
46
- head(nuxtApp) {
46
+ head (nuxtApp) {
47
47
  return {
48
- title: 'My site'
48
+ title: 'My site',
49
49
  }
50
50
  },
51
51
  })