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