@nuxt/docs-nightly 4.3.0-29356103.2f7957ac → 4.3.0-29430576.f48ea4c8

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 (250) hide show
  1. package/1.getting-started/01.introduction.md +1 -1
  2. package/1.getting-started/02.installation.md +4 -6
  3. package/1.getting-started/03.configuration.md +27 -27
  4. package/1.getting-started/04.views.md +5 -5
  5. package/1.getting-started/05.assets.md +8 -8
  6. package/1.getting-started/06.styling.md +15 -15
  7. package/1.getting-started/07.routing.md +10 -6
  8. package/1.getting-started/08.seo-meta.md +3 -3
  9. package/1.getting-started/09.transitions.md +10 -10
  10. package/1.getting-started/10.data-fetching.md +16 -16
  11. package/1.getting-started/11.state-management.md +3 -3
  12. package/1.getting-started/12.error-handling.md +6 -6
  13. package/1.getting-started/13.server.md +6 -6
  14. package/1.getting-started/14.layers.md +32 -13
  15. package/1.getting-started/16.deployment.md +1 -1
  16. package/1.getting-started/17.testing.md +36 -5
  17. package/1.getting-started/18.upgrade.md +43 -35
  18. package/{2.guide/1.directory-structure → 2.directory-structure}/0.nuxt.md +1 -1
  19. package/{2.guide/1.directory-structure → 2.directory-structure}/0.output.md +1 -1
  20. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.assets.md +2 -2
  21. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.components.md +6 -6
  22. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.composables.md +2 -2
  23. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.layouts.md +3 -3
  24. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.middleware.md +5 -5
  25. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.pages.md +17 -17
  26. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.plugins.md +3 -7
  27. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/1.utils.md +3 -3
  28. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app.md +4 -4
  29. package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.error.md +1 -3
  30. package/{2.guide/1.directory-structure → 2.directory-structure}/1.content.md +2 -2
  31. package/{2.guide/1.directory-structure → 2.directory-structure}/1.modules.md +2 -2
  32. package/{2.guide/1.directory-structure → 2.directory-structure}/1.node_modules.md +2 -2
  33. package/{2.guide/1.directory-structure → 2.directory-structure}/1.public.md +1 -1
  34. package/{2.guide/1.directory-structure → 2.directory-structure}/1.server.md +7 -7
  35. package/{2.guide/1.directory-structure → 2.directory-structure}/1.shared.md +3 -3
  36. package/{2.guide/1.directory-structure → 2.directory-structure}/2.env.md +2 -2
  37. package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtignore.md +1 -1
  38. package/{2.guide/1.directory-structure → 2.directory-structure}/2.nuxtrc.md +1 -1
  39. package/{2.guide/1.directory-structure → 2.directory-structure}/3.nuxt-config.md +1 -1
  40. package/{2.guide/1.directory-structure → 2.directory-structure}/3.package.md +1 -1
  41. package/2.directory-structure/3.tsconfig.md +69 -0
  42. package/2.directory-structure/index.md +61 -0
  43. package/{2.guide → 3.guide}/0.index.md +10 -7
  44. package/{2.guide/2.concepts/3.rendering.md → 3.guide/1.concepts/1.rendering.md} +4 -30
  45. package/{2.guide/2.concepts/2.vuejs-development.md → 3.guide/1.concepts/10.vuejs-development.md} +7 -6
  46. package/{2.guide/2.concepts/10.nuxt-lifecycle.md → 3.guide/1.concepts/2.nuxt-lifecycle.md} +32 -25
  47. package/{2.guide/2.concepts/1.auto-imports.md → 3.guide/1.concepts/3.auto-imports.md} +7 -7
  48. package/{2.guide/2.concepts → 3.guide/1.concepts}/4.server-engine.md +3 -3
  49. package/{2.guide/2.concepts → 3.guide/1.concepts}/5.modules.md +2 -2
  50. package/{2.guide/2.concepts → 3.guide/1.concepts}/7.esm.md +3 -2
  51. package/{2.guide/2.concepts → 3.guide/1.concepts}/8.typescript.md +15 -38
  52. package/{2.guide/2.concepts → 3.guide/1.concepts}/9.code-style.md +1 -1
  53. package/{2.guide/5.best-practices → 3.guide/2.best-practices}/hydration.md +1 -1
  54. package/{2.guide/5.best-practices → 3.guide/2.best-practices}/performance.md +2 -2
  55. package/3.guide/3.ai/.navigation.yml +3 -0
  56. package/3.guide/3.ai/1.mcp.md +255 -0
  57. package/3.guide/3.ai/2.llms-txt.md +65 -0
  58. package/3.guide/4.modules/.navigation.yml +3 -0
  59. package/3.guide/4.modules/1.getting-started.md +103 -0
  60. package/3.guide/4.modules/2.module-anatomy.md +138 -0
  61. package/3.guide/4.modules/3.recipes-basics.md +299 -0
  62. package/3.guide/4.modules/4.recipes-advanced.md +231 -0
  63. package/3.guide/4.modules/5.testing.md +76 -0
  64. package/3.guide/4.modules/6.best-practices.md +104 -0
  65. package/3.guide/4.modules/7.ecosystem.md +32 -0
  66. package/3.guide/4.modules/index.md +36 -0
  67. package/{2.guide/4.recipes → 3.guide/5.recipes}/1.custom-routing.md +5 -5
  68. package/{2.guide/4.recipes → 3.guide/5.recipes}/2.vite-plugin.md +1 -1
  69. package/{2.guide/4.recipes → 3.guide/5.recipes}/3.custom-usefetch.md +1 -1
  70. package/{2.guide/4.recipes → 3.guide/5.recipes}/4.sessions-and-authentication.md +1 -1
  71. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.events.md +2 -3
  72. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.experimental-features.md +10 -10
  73. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.features.md +1 -1
  74. package/{2.guide/3.going-further → 3.guide/6.going-further}/1.internals.md +5 -4
  75. package/{2.guide/3.going-further → 3.guide/6.going-further}/10.runtime-config.md +2 -2
  76. package/{2.guide/3.going-further → 3.guide/6.going-further}/2.hooks.md +3 -3
  77. package/{2.guide/3.going-further → 3.guide/6.going-further}/4.kit.md +1 -1
  78. package/{2.guide/3.going-further → 3.guide/6.going-further}/6.nuxt-app.md +5 -5
  79. package/{2.guide/3.going-further → 3.guide/6.going-further}/7.layers.md +42 -25
  80. package/{2.guide/3.going-further → 3.guide/6.going-further}/9.debugging.md +1 -1
  81. package/{3.api → 4.api}/1.components/10.nuxt-picture.md +1 -1
  82. package/{3.api → 4.api}/1.components/11.teleports.md +1 -1
  83. package/{3.api → 4.api}/1.components/12.nuxt-route-announcer.md +1 -3
  84. package/{3.api → 4.api}/1.components/13.nuxt-time.md +0 -2
  85. package/{3.api → 4.api}/1.components/2.nuxt-page.md +3 -3
  86. package/{3.api → 4.api}/1.components/3.nuxt-layout.md +5 -5
  87. package/{3.api → 4.api}/1.components/4.nuxt-link.md +11 -11
  88. package/{3.api → 4.api}/1.components/5.nuxt-loading-indicator.md +1 -1
  89. package/{3.api → 4.api}/1.components/6.nuxt-error-boundary.md +1 -1
  90. package/{3.api → 4.api}/1.components/7.nuxt-welcome.md +2 -2
  91. package/{3.api → 4.api}/2.composables/use-app-config.md +1 -1
  92. package/{3.api → 4.api}/2.composables/use-async-data.md +76 -13
  93. package/4.api/2.composables/use-cookie.md +183 -0
  94. package/{3.api → 4.api}/2.composables/use-fetch.md +33 -33
  95. package/{3.api → 4.api}/2.composables/use-head-safe.md +37 -20
  96. package/4.api/2.composables/use-head.md +184 -0
  97. package/{3.api → 4.api}/2.composables/use-hydration.md +24 -18
  98. package/4.api/2.composables/use-lazy-async-data.md +96 -0
  99. package/4.api/2.composables/use-lazy-fetch.md +111 -0
  100. package/{3.api → 4.api}/2.composables/use-nuxt-app.md +7 -7
  101. package/{3.api → 4.api}/2.composables/use-nuxt-data.md +1 -1
  102. package/{3.api → 4.api}/2.composables/use-request-fetch.md +1 -1
  103. package/{3.api → 4.api}/2.composables/use-response-header.md +1 -1
  104. package/{3.api → 4.api}/2.composables/use-route-announcer.md +0 -2
  105. package/{3.api → 4.api}/2.composables/use-route.md +2 -2
  106. package/4.api/2.composables/use-router.md +94 -0
  107. package/{3.api → 4.api}/2.composables/use-runtime-config.md +1 -1
  108. package/{3.api → 4.api}/2.composables/use-runtime-hook.md +1 -1
  109. package/{3.api → 4.api}/2.composables/use-state.md +1 -1
  110. package/{3.api → 4.api}/3.utils/$fetch.md +1 -1
  111. package/{3.api → 4.api}/3.utils/abort-navigation.md +3 -3
  112. package/{3.api → 4.api}/3.utils/add-route-middleware.md +1 -1
  113. package/{3.api → 4.api}/3.utils/call-once.md +0 -2
  114. package/{3.api → 4.api}/3.utils/define-lazy-hydration-component.md +4 -4
  115. package/{3.api → 4.api}/3.utils/define-nuxt-component.md +1 -1
  116. package/4.api/3.utils/define-nuxt-plugin.md +102 -0
  117. package/{3.api → 4.api}/3.utils/define-nuxt-route-middleware.md +2 -2
  118. package/{3.api → 4.api}/3.utils/define-page-meta.md +14 -14
  119. package/{3.api → 4.api}/3.utils/navigate-to.md +15 -15
  120. package/{3.api → 4.api}/3.utils/on-before-route-leave.md +1 -1
  121. package/{3.api → 4.api}/3.utils/on-before-route-update.md +1 -1
  122. package/{3.api → 4.api}/3.utils/refresh-cookie.md +1 -3
  123. package/{3.api → 4.api}/3.utils/update-app-config.md +2 -2
  124. package/{3.api → 4.api}/4.commands/add.md +11 -11
  125. package/4.api/4.commands/analyze.md +42 -0
  126. package/4.api/4.commands/build-module.md +42 -0
  127. package/4.api/4.commands/build.md +47 -0
  128. package/{3.api → 4.api}/4.commands/cleanup.md +6 -6
  129. package/4.api/4.commands/dev.md +60 -0
  130. package/{3.api → 4.api}/4.commands/devtools.md +7 -7
  131. package/4.api/4.commands/generate.md +42 -0
  132. package/4.api/4.commands/info.md +33 -0
  133. package/4.api/4.commands/init.md +50 -0
  134. package/4.api/4.commands/module.md +84 -0
  135. package/4.api/4.commands/prepare.md +41 -0
  136. package/4.api/4.commands/preview.md +44 -0
  137. package/4.api/4.commands/test.md +40 -0
  138. package/4.api/4.commands/typecheck.md +44 -0
  139. package/4.api/4.commands/upgrade.md +37 -0
  140. package/{3.api → 4.api}/5.kit/1.modules.md +18 -18
  141. package/{3.api → 4.api}/5.kit/10.templates.md +23 -23
  142. package/{3.api → 4.api}/5.kit/11.nitro.md +35 -35
  143. package/{3.api → 4.api}/5.kit/14.builder.md +21 -21
  144. package/{3.api → 4.api}/5.kit/16.layers.md +12 -12
  145. package/{3.api → 4.api}/5.kit/2.programmatic.md +2 -2
  146. package/{3.api → 4.api}/5.kit/4.autoimports.md +18 -18
  147. package/4.api/5.kit/5.components.md +146 -0
  148. package/4.api/6.advanced/1.hooks.md +105 -0
  149. package/{3.api → 4.api}/6.nuxt-config.md +29 -28
  150. package/5.community/3.reporting-bugs.md +1 -1
  151. package/5.community/4.contribution.md +4 -4
  152. package/5.community/5.framework-contribution.md +8 -8
  153. package/5.community/6.roadmap.md +25 -25
  154. package/5.community/7.changelog.md +10 -0
  155. package/6.bridge/1.overview.md +1 -1
  156. package/6.bridge/2.typescript.md +1 -1
  157. package/6.bridge/3.bridge-composition-api.md +1 -1
  158. package/6.bridge/4.plugins-and-middleware.md +2 -2
  159. package/7.migration/11.server.md +1 -1
  160. package/7.migration/2.configuration.md +5 -5
  161. package/7.migration/20.module-authors.md +3 -3
  162. package/7.migration/3.auto-imports.md +1 -1
  163. package/7.migration/5.plugins-and-middleware.md +2 -2
  164. package/7.migration/6.pages-and-layouts.md +6 -6
  165. package/README.md +1 -1
  166. package/package.json +1 -1
  167. package/2.guide/1.directory-structure/3.tsconfig.md +0 -38
  168. package/2.guide/3.going-further/3.modules.md +0 -901
  169. package/3.api/2.composables/use-cookie.md +0 -183
  170. package/3.api/2.composables/use-head.md +0 -69
  171. package/3.api/2.composables/use-lazy-async-data.md +0 -47
  172. package/3.api/2.composables/use-lazy-fetch.md +0 -55
  173. package/3.api/2.composables/use-router.md +0 -94
  174. package/3.api/3.utils/define-nuxt-plugin.md +0 -102
  175. package/3.api/4.commands/analyze.md +0 -42
  176. package/3.api/4.commands/build-module.md +0 -42
  177. package/3.api/4.commands/build.md +0 -47
  178. package/3.api/4.commands/dev.md +0 -60
  179. package/3.api/4.commands/generate.md +0 -42
  180. package/3.api/4.commands/info.md +0 -33
  181. package/3.api/4.commands/init.md +0 -50
  182. package/3.api/4.commands/module.md +0 -84
  183. package/3.api/4.commands/prepare.md +0 -41
  184. package/3.api/4.commands/preview.md +0 -44
  185. package/3.api/4.commands/test.md +0 -40
  186. package/3.api/4.commands/typecheck.md +0 -44
  187. package/3.api/4.commands/upgrade.md +0 -37
  188. package/3.api/5.kit/5.components.md +0 -146
  189. package/3.api/6.advanced/1.hooks.md +0 -105
  190. /package/{2.guide/1.directory-structure → 2.directory-structure}/.navigation.yml +0 -0
  191. /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/.navigation.yml +0 -0
  192. /package/{2.guide/1.directory-structure → 2.directory-structure}/1.app/3.app-config.md +0 -0
  193. /package/{2.guide/1.directory-structure → 2.directory-structure}/2.gitignore.md +0 -0
  194. /package/{2.guide → 3.guide}/.navigation.yml +0 -0
  195. /package/{2.guide/2.concepts → 3.guide/1.concepts}/.navigation.yml +0 -0
  196. /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/.navigation.yml +0 -0
  197. /package/{2.guide/5.best-practices → 3.guide/2.best-practices}/plugins.md +0 -0
  198. /package/{2.guide/4.recipes → 3.guide/5.recipes}/.navigation.yml +0 -0
  199. /package/{2.guide/3.going-further → 3.guide/6.going-further}/.navigation.yml +0 -0
  200. /package/{2.guide/3.going-further → 3.guide/6.going-further}/11.nightly-release-channel.md +0 -0
  201. /package/{2.guide/3.going-further → 3.guide/6.going-further}/index.md +0 -0
  202. /package/{3.api → 4.api}/.navigation.yml +0 -0
  203. /package/{3.api → 4.api}/1.components/.navigation.yml +0 -0
  204. /package/{3.api → 4.api}/1.components/1.client-only.md +0 -0
  205. /package/{3.api → 4.api}/1.components/1.dev-only.md +0 -0
  206. /package/{3.api → 4.api}/1.components/1.nuxt-client-fallback.md +0 -0
  207. /package/{3.api → 4.api}/1.components/8.nuxt-island.md +0 -0
  208. /package/{3.api → 4.api}/1.components/9.nuxt-img.md +0 -0
  209. /package/{3.api → 4.api}/2.composables/.navigation.yml +0 -0
  210. /package/{3.api → 4.api}/2.composables/on-prehydrate.md +0 -0
  211. /package/{3.api → 4.api}/2.composables/use-error.md +0 -0
  212. /package/{3.api → 4.api}/2.composables/use-loading-indicator.md +0 -0
  213. /package/{3.api → 4.api}/2.composables/use-preview-mode.md +0 -0
  214. /package/{3.api → 4.api}/2.composables/use-request-event.md +0 -0
  215. /package/{3.api → 4.api}/2.composables/use-request-header.md +0 -0
  216. /package/{3.api → 4.api}/2.composables/use-request-headers.md +0 -0
  217. /package/{3.api → 4.api}/2.composables/use-request-url.md +0 -0
  218. /package/{3.api → 4.api}/2.composables/use-seo-meta.md +0 -0
  219. /package/{3.api → 4.api}/2.composables/use-server-seo-meta.md +0 -0
  220. /package/{3.api → 4.api}/3.utils/.navigation.yml +0 -0
  221. /package/{3.api → 4.api}/3.utils/clear-error.md +0 -0
  222. /package/{3.api → 4.api}/3.utils/clear-nuxt-data.md +0 -0
  223. /package/{3.api → 4.api}/3.utils/clear-nuxt-state.md +0 -0
  224. /package/{3.api → 4.api}/3.utils/create-error.md +0 -0
  225. /package/{3.api → 4.api}/3.utils/define-route-rules.md +0 -0
  226. /package/{3.api → 4.api}/3.utils/on-nuxt-ready.md +0 -0
  227. /package/{3.api → 4.api}/3.utils/prefetch-components.md +0 -0
  228. /package/{3.api → 4.api}/3.utils/preload-components.md +0 -0
  229. /package/{3.api → 4.api}/3.utils/preload-route-components.md +0 -0
  230. /package/{3.api → 4.api}/3.utils/prerender-routes.md +0 -0
  231. /package/{3.api → 4.api}/3.utils/refresh-nuxt-data.md +0 -0
  232. /package/{3.api → 4.api}/3.utils/reload-nuxt-app.md +0 -0
  233. /package/{3.api → 4.api}/3.utils/set-page-layout.md +0 -0
  234. /package/{3.api → 4.api}/3.utils/set-response-status.md +0 -0
  235. /package/{3.api → 4.api}/3.utils/show-error.md +0 -0
  236. /package/{3.api → 4.api}/4.commands/.navigation.yml +0 -0
  237. /package/{3.api → 4.api}/5.kit/.navigation.yml +0 -0
  238. /package/{3.api → 4.api}/5.kit/10.runtime-config.md +0 -0
  239. /package/{3.api → 4.api}/5.kit/12.resolving.md +0 -0
  240. /package/{3.api → 4.api}/5.kit/13.logging.md +0 -0
  241. /package/{3.api → 4.api}/5.kit/15.examples.md +0 -0
  242. /package/{3.api → 4.api}/5.kit/3.compatibility.md +0 -0
  243. /package/{3.api → 4.api}/5.kit/6.context.md +0 -0
  244. /package/{3.api → 4.api}/5.kit/7.pages.md +0 -0
  245. /package/{3.api → 4.api}/5.kit/8.layout.md +0 -0
  246. /package/{3.api → 4.api}/5.kit/9.head.md +0 -0
  247. /package/{3.api → 4.api}/5.kit/9.plugins.md +0 -0
  248. /package/{3.api → 4.api}/6.advanced/.navigation.yml +0 -0
  249. /package/{3.api → 4.api}/6.advanced/2.import-meta.md +0 -0
  250. /package/{3.api → 4.api}/index.md +0 -0
@@ -100,7 +100,7 @@ If you encounter the `data` variable destructured from a `useFetch` returns a st
100
100
 
101
101
  ### Reactive Fetch Options
102
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.
103
+ Fetch options can be provided as reactive, supporting `computed`, `ref` and [computed getters](https://vuejs.org/guide/essentials/computed). When a reactive fetch option is updated it will trigger a refetch using the updated resolved reactive value.
104
104
 
105
105
  ```ts
106
106
  const searchQuery = ref('initial')
@@ -128,7 +128,7 @@ searchQuery.value = 'new search'
128
128
  ```ts [Signature]
129
129
  export function useFetch<DataT, ErrorT> (
130
130
  url: string | Request | Ref<string | Request> | (() => string | Request),
131
- options?: UseFetchOptions<DataT>
131
+ options?: UseFetchOptions<DataT>,
132
132
  ): Promise<AsyncData<DataT, ErrorT>>
133
133
 
134
134
  type UseFetchOptions<DataT> = {
@@ -183,29 +183,29 @@ type AsyncDataRequestStatus = 'idle' | 'pending' | 'success' | 'error'
183
183
 
184
184
  - `options` (object): Configuration for the fetch request. Extends [unjs/ofetch](https://github.com/unjs/ofetch) options and [`AsyncDataOptions`](/docs/4.x/api/composables/use-async-data#params). All options can be a static value, a `ref`, or a computed value.
185
185
 
186
- | Option | Type | Default | Description |
187
- | ---| --- | --- | --- |
188
- | `key` | `MaybeRefOrGetter<string>` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
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. |
196
- | `cache` | `boolean \| string` | - | Cache control. Boolean disables cache, or use Fetch API values: `default`, `no-store`, etc. |
197
- | `server` | `boolean` | `true` | Whether to fetch on the server. |
198
- | `lazy` | `boolean` | `false` | If true, resolves after route loads (does not block navigation). |
199
- | `immediate` | `boolean` | `true` | If false, prevents request from firing immediately. |
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) |
202
- | `transform` | `(input: DataT) => DataT \| Promise<DataT>` | - | Function to transform the result after resolving. |
203
- | `getCachedData`| `(key, nuxtApp, ctx) => DataT \| undefined` | - | Function to return cached data. See below for default. |
204
- | `pick` | `string[]` | - | Only pick specified keys from the result. |
205
- | `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
206
- | `deep` | `boolean` | `false` | Return data in a deep ref object. |
207
- | `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
208
- | `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. See [Custom useFetch in Nuxt](/docs/4.x/guide/recipes/custom-usefetch) |
186
+ | Option | Type | Default | Description |
187
+ |-----------------|-------------------------------------------------------------------------|------------|------------------------------------------------------------------------------------------------------------------|
188
+ | `key` | `MaybeRefOrGetter<string>` | auto-gen | Unique key for de-duplication. If not provided, generated from URL and options. |
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. |
196
+ | `cache` | `boolean \| string` | - | Cache control. Boolean disables cache, or use Fetch API values: `default`, `no-store`, etc. |
197
+ | `server` | `boolean` | `true` | Whether to fetch on the server. |
198
+ | `lazy` | `boolean` | `false` | If true, resolves after route loads (does not block navigation). |
199
+ | `immediate` | `boolean` | `true` | If false, prevents request from firing immediately. |
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) |
202
+ | `transform` | `(input: DataT) => DataT \| Promise<DataT>` | - | Function to transform the result after resolving. |
203
+ | `getCachedData` | `(key, nuxtApp, ctx) => DataT \| undefined` | - | Function to return cached data. See below for default. |
204
+ | `pick` | `string[]` | - | Only pick specified keys from the result. |
205
+ | `watch` | `MultiWatchSources \| false` | - | Array of reactive sources to watch and auto-refresh. `false` disables watching. |
206
+ | `deep` | `boolean` | `false` | Return data in a deep ref object. |
207
+ | `dedupe` | `'cancel' \| 'defer'` | `'cancel'` | Avoid fetching same key more than once at a time. |
208
+ | `$fetch` | `typeof globalThis.$fetch` | - | Custom $fetch implementation. See [Custom useFetch in Nuxt](/docs/4.x/guide/recipes/custom-usefetch) |
209
209
 
210
210
  ::note
211
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.
@@ -222,14 +222,14 @@ This only caches data when `experimental.payloadExtraction` in `nuxt.config` is
222
222
 
223
223
  ## Return Values
224
224
 
225
- | Name | Type | Description |
226
- | --- | --- |--- |
227
- | `data` | `Ref<DataT \| undefined>` | The result of the asynchronous fetch. |
228
- | `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. By default, Nuxt waits until a `refresh` is finished before it can be executed again. |
229
- | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
230
- | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
231
- | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. See below for possible values. |
232
- | `clear` | `() => void` | Resets `data` to `undefined` (or the value of `options.default()` if provided), `error` to `undefined`, set `status` to `idle`, and cancels any pending requests. |
225
+ | Name | Type | Description |
226
+ |-----------|-----------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
227
+ | `data` | `Ref<DataT \| undefined>` | The result of the asynchronous fetch. |
228
+ | `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. By default, Nuxt waits until a `refresh` is finished before it can be executed again. |
229
+ | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
230
+ | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
231
+ | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. See below for possible values. |
232
+ | `clear` | `() => void` | Resets `data` to `undefined` (or the value of `options.default()` if provided), `error` to `undefined`, set `status` to `idle`, and cancels any pending requests. |
233
233
 
234
234
  ### Status values
235
235
 
@@ -8,28 +8,12 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
- The `useHeadSafe` composable is a wrapper around the [`useHead`](/docs/4.x/api/composables/use-head) composable that restricts the input to only allow safe values.
12
-
13
11
  ## Usage
14
12
 
15
- You can pass all the same values as [`useHead`](/docs/4.x/api/composables/use-head)
16
-
17
- ```ts
18
- useHeadSafe({
19
- script: [
20
- { id: 'xss-script', innerHTML: 'alert("xss")' },
21
- ],
22
- meta: [
23
- { 'http-equiv': 'refresh', 'content': '0;javascript:alert(1)' },
24
- ],
25
- })
26
- // Will safely generate
27
- // <script id="xss-script"></script>
28
- // <meta content="0;javascript:alert(1)">
29
- ```
13
+ The `useHeadSafe` composable is a wrapper around the [`useHead`](/docs/4.x/api/composables/use-head) composable that restricts the input to only allow safe values. This is the recommended way to manage head data when working with user input, as it prevents XSS attacks by sanitizing potentially dangerous attributes.
30
14
 
31
- ::read-more{to="https://unhead.unjs.io/docs/typescript/head/api/composables/use-head-safe" target="_blank"}
32
- Read more on the `Unhead` documentation.
15
+ ::warning
16
+ When using `useHeadSafe`, potentially dangerous attributes like `innerHTML` in scripts or `http-equiv` in meta tags are automatically stripped out to prevent XSS attacks. Use this composable whenever you're working with user-generated content.
33
17
  ::
34
18
 
35
19
  ## Type
@@ -38,7 +22,9 @@ Read more on the `Unhead` documentation.
38
22
  export function useHeadSafe (input: MaybeComputedRef<HeadSafe>): void
39
23
  ```
40
24
 
41
- The list of allowed values is:
25
+ ### Allowed Attributes
26
+
27
+ The following attributes are whitelisted for each head element type:
42
28
 
43
29
  ```ts
44
30
  const WhitelistAttributes = {
@@ -53,3 +39,34 @@ const WhitelistAttributes = {
53
39
  ```
54
40
 
55
41
  See [@unhead/vue](https://github.com/unjs/unhead/blob/main/packages/vue/src/types/safeSchema.ts) for more detailed types.
42
+
43
+ ## Parameters
44
+
45
+ `input`: A `MaybeComputedRef<HeadSafe>` object containing head data. You can pass all the same values as [`useHead`](/docs/4.x/api/composables/use-head), but only safe attributes will be rendered.
46
+
47
+ ## Return Values
48
+
49
+ This composable does not return any value.
50
+
51
+ ## Example
52
+
53
+ ```vue [app/pages/user-profile.vue]
54
+ <script setup lang="ts">
55
+ // User-generated content that might contain malicious code
56
+ const userBio = ref('<script>alert("xss")<' + '/script>')
57
+
58
+ useHeadSafe({
59
+ title: `User Profile`,
60
+ meta: [
61
+ {
62
+ name: 'description',
63
+ content: userBio.value, // Safely sanitized
64
+ },
65
+ ],
66
+ })
67
+ </script>
68
+ ```
69
+
70
+ ::read-more{to="https://unhead.unjs.io/docs/typescript/head/api/composables/use-head-safe" target="_blank"}
71
+ Read more on the `Unhead` documentation.
72
+ ::
@@ -0,0 +1,184 @@
1
+ ---
2
+ title: useHead
3
+ description: useHead customizes the head properties of individual pages of your Nuxt app.
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
+ ## Usage
12
+
13
+ The `useHead` composable allows you to manage your head tags in a programmatic and reactive way, powered by [Unhead](https://unhead.unjs.io). It lets you customize the meta tags, links, scripts, and other elements in the `<head>` section of your HTML document.
14
+
15
+ ```vue [app/app.vue]
16
+ <script setup lang="ts">
17
+ useHead({
18
+ title: 'My App',
19
+ meta: [
20
+ { name: 'description', content: 'My amazing site.' },
21
+ ],
22
+ bodyAttrs: {
23
+ class: 'test',
24
+ },
25
+ script: [{ innerHTML: 'console.log(\'Hello world\')' }],
26
+ })
27
+ </script>
28
+ ```
29
+
30
+ ::warning
31
+ If the data comes from a user or other untrusted source, we recommend you check out [`useHeadSafe`](/docs/4.x/api/composables/use-head-safe).
32
+ ::
33
+
34
+ ::note
35
+ The properties of `useHead` can be dynamic, accepting `ref`, `computed` and `reactive` properties. The `meta` parameter can also accept a function returning an object to make the entire object reactive.
36
+ ::
37
+
38
+ ## Type
39
+
40
+ ```ts [Signature]
41
+ export function useHead (meta: MaybeComputedRef<MetaObject>): ActiveHeadEntry<UseHeadInput>
42
+
43
+ interface MetaObject {
44
+ title?: string
45
+ titleTemplate?: string | ((title?: string) => string)
46
+ base?: Base
47
+ link?: Link[]
48
+ meta?: Meta[]
49
+ style?: Style[]
50
+ script?: Script[]
51
+ noscript?: Noscript[]
52
+ htmlAttrs?: HtmlAttributes
53
+ bodyAttrs?: BodyAttributes
54
+ }
55
+
56
+ interface ActiveHeadEntry<Input> {
57
+ /**
58
+ * Updates the entry with new input.
59
+ *
60
+ * Will first clear any side effects for previous input.
61
+ */
62
+ patch: (input: Input) => void
63
+ /**
64
+ * Dispose the entry, removing it from the active head.
65
+ *
66
+ * Will queue side effects for removal.
67
+ */
68
+ dispose: () => void
69
+ }
70
+ ```
71
+
72
+ See [@unhead/schema](https://github.com/unjs/unhead/blob/main/packages/vue/src/types/schema.ts) for more detailed types.
73
+
74
+ ## Parameters
75
+
76
+ `meta`: An object accepting head metadata properties to customize the page's `<head>` section. All properties support reactive values (`ref`, `computed`, `reactive`) or can be a function returning the metadata object.
77
+
78
+ | Property | Type | Description |
79
+ | --- | --- | --- |
80
+ | `title` | `string` | Sets the page title. |
81
+ | `titleTemplate` | `string \| ((title?: string) => string)` | Configures a dynamic template to customize the page title. Can be a string with `%s` placeholder or a function. |
82
+ | `base` | `Base` | Sets the `<base>` tag for the document. |
83
+ | `link` | `Link[]` | Array of link objects. Each element is mapped to a `<link>` tag, where object properties correspond to HTML attributes. |
84
+ | `meta` | `Meta[]` | Array of meta objects. Each element is mapped to a `<meta>` tag, where object properties correspond to HTML attributes. |
85
+ | `style` | `Style[]` | Array of style objects. Each element is mapped to a `<style>` tag, where object properties correspond to HTML attributes. |
86
+ | `script` | `Script[]` | Array of script objects. Each element is mapped to a `<script>` tag, where object properties correspond to HTML attributes. |
87
+ | `noscript` | `Noscript[]` | Array of noscript objects. Each element is mapped to a `<noscript>` tag, where object properties correspond to HTML attributes. |
88
+ | `htmlAttrs` | `HtmlAttributes` | Sets attributes of the `<html>` tag. Each object property is mapped to the corresponding attribute. |
89
+ | `bodyAttrs` | `BodyAttributes` | Sets attributes of the `<body>` tag. Each object property is mapped to the corresponding attribute. |
90
+
91
+ ## Return Values
92
+
93
+ This composable does not return any value. It registers the head metadata with Unhead, which manages the actual DOM updates.
94
+
95
+ ## Examples
96
+
97
+ ### Basic Meta Tags
98
+
99
+ ```vue [app/pages/about.vue]
100
+ <script setup lang="ts">
101
+ useHead({
102
+ title: 'About Us',
103
+ meta: [
104
+ { name: 'description', content: 'Learn more about our company' },
105
+ { property: 'og:title', content: 'About Us' },
106
+ { property: 'og:description', content: 'Learn more about our company' },
107
+ ],
108
+ })
109
+ </script>
110
+ ```
111
+
112
+ ### Reactive Meta Tags
113
+
114
+ ```vue [app/pages/profile.vue]
115
+ <script setup lang="ts">
116
+ const profile = ref({ name: 'John Doe' })
117
+
118
+ useHead({
119
+ title: computed(() => profile.value.name),
120
+ meta: [
121
+ {
122
+ name: 'description',
123
+ content: computed(() => `Profile page for ${profile.value.name}`),
124
+ },
125
+ ],
126
+ })
127
+ </script>
128
+ ```
129
+
130
+ ### Using a Function for Full Reactivity
131
+
132
+ ```vue [app/pages/dynamic.vue]
133
+ <script setup lang="ts">
134
+ const count = ref(0)
135
+
136
+ useHead(() => ({
137
+ title: `Count: ${count.value}`,
138
+ meta: [
139
+ { name: 'description', content: `Current count is ${count.value}` },
140
+ ],
141
+ }))
142
+ </script>
143
+ ```
144
+
145
+ ### Adding External Scripts and Styles
146
+
147
+ ```vue [app/pages/external.vue]
148
+ <script setup lang="ts">
149
+ useHead({
150
+ link: [
151
+ {
152
+ rel: 'stylesheet',
153
+ href: 'https://cdn.example.com/styles.css',
154
+ },
155
+ ],
156
+ script: [
157
+ {
158
+ src: 'https://cdn.example.com/script.js',
159
+ async: true,
160
+ },
161
+ ],
162
+ })
163
+ </script>
164
+ ```
165
+
166
+ ### Body and HTML Attributes
167
+
168
+ ```vue [app/pages/themed.vue]
169
+ <script setup lang="ts">
170
+ const isDark = ref(true)
171
+
172
+ useHead({
173
+ htmlAttrs: {
174
+ lang: 'en',
175
+ class: computed(() => isDark.value ? 'dark' : 'light'),
176
+ },
177
+ bodyAttrs: {
178
+ class: 'themed-page',
179
+ },
180
+ })
181
+ </script>
182
+ ```
183
+
184
+ :read-more{to="/docs/4.x/getting-started/seo-meta"}
@@ -8,6 +8,8 @@ links:
8
8
  size: xs
9
9
  ---
10
10
 
11
+ `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.
12
+
11
13
  ::note
12
14
  This is an advanced composable, primarily designed for use within plugins, mostly used by Nuxt modules.
13
15
  ::
@@ -16,14 +18,24 @@ This is an advanced composable, primarily designed for use within plugins, mostl
16
18
  `useHydration` is designed to **ensure state synchronization and restoration during SSR**. If you need to create a globally reactive state that is SSR-friendly in Nuxt, [`useState`](/docs/4.x/api/composables/use-state) is the recommended choice.
17
19
  ::
18
20
 
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.
21
+ ## Usage
20
22
 
21
23
  The data returned from the `get` function on the server is stored in `nuxtApp.payload` under the unique key provided as the first parameter to `useHydration`. During hydration, this data is then retrieved on the client, preventing redundant computations or API calls.
22
24
 
23
- ## Usage
24
-
25
25
  ::code-group
26
26
 
27
+ ```ts [With useHydration]
28
+ export default defineNuxtPlugin((nuxtApp) => {
29
+ const myStore = new MyStore()
30
+
31
+ useHydration(
32
+ 'myStoreState',
33
+ () => myStore.getState(),
34
+ data => myStore.setState(data),
35
+ )
36
+ })
37
+ ```
38
+
27
39
  ```ts [Without useHydration]
28
40
  export default defineNuxtPlugin((nuxtApp) => {
29
41
  const myStore = new MyStore()
@@ -41,18 +53,6 @@ export default defineNuxtPlugin((nuxtApp) => {
41
53
  }
42
54
  })
43
55
  ```
44
-
45
- ```ts [With useHydration]
46
- export default defineNuxtPlugin((nuxtApp) => {
47
- const myStore = new MyStore()
48
-
49
- useHydration(
50
- 'myStoreState',
51
- () => myStore.getState(),
52
- data => myStore.setState(data),
53
- )
54
- })
55
- ```
56
56
  ::
57
57
 
58
58
  ## Type
@@ -63,6 +63,12 @@ export function useHydration<T> (key: string, get: () => T, set: (value: T) => v
63
63
 
64
64
  ## Parameters
65
65
 
66
- - `key`: A unique key that identifies the data in your Nuxt application.
67
- - `get`: A function executed **only on the server** (called when SSR rendering is done) to set the initial value.
68
- - `set`: A function executed **only on the client** (called when initial vue instance is created) to receive the data.
66
+ | Parameter | Type | Description |
67
+ | --- | --- | --- |
68
+ | `key` | `string` | A unique key that identifies the data in your Nuxt application. |
69
+ | `get` | `() => T` | A function executed **only on the server** (called when SSR rendering is done) to set the initial value. |
70
+ | `set` | `(value: T) => void` | A function executed **only on the client** (called when initial Vue instance is created) to receive the data. |
71
+
72
+ ## Return Values
73
+
74
+ This composable does not return any value.
@@ -0,0 +1,96 @@
1
+ ---
2
+ title: useLazyAsyncData
3
+ description: This wrapper around useAsyncData triggers navigation immediately.
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/asyncData.ts
8
+ size: xs
9
+ ---
10
+
11
+ `useLazyAsyncData` provides a wrapper around [`useAsyncData`](/docs/4.x/api/composables/use-async-data) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
12
+
13
+ ::note
14
+ By default, [`useAsyncData`](/docs/4.x/api/composables/use-async-data) blocks navigation until its async handler is resolved. `useLazyAsyncData` allows navigation to occur immediately while data fetching continues in the background.
15
+ ::
16
+
17
+ ## Usage
18
+
19
+ ```vue [app/pages/index.vue]
20
+ <script setup lang="ts">
21
+ const { status, data: posts } = await useLazyAsyncData('posts', () => $fetch('/api/posts'))
22
+ </script>
23
+
24
+ <template>
25
+ <div>
26
+ <div v-if="status === 'pending'">
27
+ Loading...
28
+ </div>
29
+ <div v-else-if="status === 'error'">
30
+ Error loading posts
31
+ </div>
32
+ <div v-else>
33
+ {{ posts }}
34
+ </div>
35
+ </div>
36
+ </template>
37
+ ```
38
+
39
+ When using `useLazyAsyncData`, navigation will occur before fetching is complete. This means you must handle `pending` and `error` states directly within your component's template.
40
+
41
+ ::warning
42
+ `useLazyAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyAsyncData`.
43
+ ::
44
+
45
+ ## Type
46
+
47
+ ```ts [Signature]
48
+ export function useLazyAsyncData<DataT, ErrorT> (
49
+ handler: (ctx?: NuxtApp) => Promise<DataT>,
50
+ options?: AsyncDataOptions<DataT>,
51
+ ): AsyncData<DataT, ErrorT>
52
+
53
+ export function useLazyAsyncData<DataT, ErrorT> (
54
+ key: string,
55
+ handler: (ctx?: NuxtApp) => Promise<DataT>,
56
+ options?: AsyncDataOptions<DataT>,
57
+ ): AsyncData<DataT, ErrorT>
58
+ ```
59
+
60
+ `useLazyAsyncData` has the same signature as [`useAsyncData`](/docs/4.x/api/composables/use-async-data).
61
+
62
+ ## Parameters
63
+
64
+ `useLazyAsyncData` accepts the same parameters as [`useAsyncData`](/docs/4.x/api/composables/use-async-data), with the `lazy` option automatically set to `true`.
65
+
66
+ :read-more{to="/docs/4.x/api/composables/use-async-data#parameters"}
67
+
68
+ ## Return Values
69
+
70
+ `useLazyAsyncData` returns the same values as [`useAsyncData`](/docs/4.x/api/composables/use-async-data).
71
+
72
+ :read-more{to="/docs/4.x/api/composables/use-async-data#return-values"}
73
+
74
+ ## Example
75
+
76
+ ```vue [app/pages/index.vue]
77
+ <script setup lang="ts">
78
+ /* Navigation will occur before fetching is complete.
79
+ Handle 'pending' and 'error' states directly within your component's template
80
+ */
81
+ const { status, data: count } = await useLazyAsyncData('count', () => $fetch('/api/count'))
82
+
83
+ watch(count, (newCount) => {
84
+ // Because count might start out null, you won't have access
85
+ // to its contents immediately, but you can watch it.
86
+ })
87
+ </script>
88
+
89
+ <template>
90
+ <div>
91
+ {{ status === 'pending' ? 'Loading' : count }}
92
+ </div>
93
+ </template>
94
+ ```
95
+
96
+ :read-more{to="/docs/4.x/getting-started/data-fetching"}
@@ -0,0 +1,111 @@
1
+ ---
2
+ title: 'useLazyFetch'
3
+ description: This wrapper around useFetch triggers navigation immediately.
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/fetch.ts
8
+ size: xs
9
+ ---
10
+
11
+ `useLazyFetch` provides a wrapper around [`useFetch`](/docs/4.x/api/composables/use-fetch) that triggers navigation before the handler is resolved by setting the `lazy` option to `true`.
12
+
13
+ ## Usage
14
+
15
+ By default, [`useFetch`](/docs/4.x/api/composables/use-fetch) blocks navigation until its async handler is resolved. `useLazyFetch` allows navigation to proceed immediately, with data being fetched in the background.
16
+
17
+ ```vue [app/pages/index.vue]
18
+ <script setup lang="ts">
19
+ const { status, data: posts } = await useLazyFetch('/api/posts')
20
+ </script>
21
+
22
+ <template>
23
+ <div v-if="status === 'pending'">
24
+ Loading ...
25
+ </div>
26
+ <div v-else>
27
+ <div v-for="post in posts">
28
+ <!-- do something -->
29
+ </div>
30
+ </div>
31
+ </template>
32
+ ```
33
+
34
+ ::note
35
+ `useLazyFetch` has the same signature as [`useFetch`](/docs/4.x/api/composables/use-fetch).
36
+ ::
37
+
38
+ ::warning
39
+ Awaiting `useLazyFetch` only ensures the call is initialized. On client-side navigation, data may not be immediately available, and you must handle the `pending` state in your component's template.
40
+ ::
41
+
42
+ ::warning
43
+ `useLazyFetch` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyFetch`.
44
+ ::
45
+
46
+ ## Type
47
+
48
+ ```ts [Signature]
49
+ export function useLazyFetch<DataT, ErrorT> (
50
+ url: string | Request | Ref<string | Request> | (() => string | Request),
51
+ options?: UseFetchOptions<DataT>,
52
+ ): Promise<AsyncData<DataT, ErrorT>>
53
+ ```
54
+
55
+ ::note
56
+ `useLazyFetch` is equivalent to `useFetch` with `lazy: true` option set. See [`useFetch`](/docs/4.x/api/composables/use-fetch) for full type definitions.
57
+ ::
58
+
59
+ ## Parameters
60
+
61
+ `useLazyFetch` accepts the same parameters as [`useFetch`](/docs/4.x/api/composables/use-fetch):
62
+
63
+ - `URL` (`string | Request | Ref<string | Request> | () => string | Request`): The URL or request to fetch.
64
+ - `options` (object): Same as [`useFetch` options](/docs/4.x/api/composables/use-fetch#parameters), with `lazy` automatically set to `true`.
65
+
66
+ :read-more{to="/docs/4.x/api/composables/use-fetch#parameters"}
67
+
68
+ ## Return Values
69
+
70
+ Returns the same `AsyncData` object as [`useFetch`](/docs/4.x/api/composables/use-fetch):
71
+
72
+ | Name | Type | Description |
73
+ |-----------|-----------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
74
+ | `data` | `Ref<DataT \| undefined>` | The result of the asynchronous fetch. |
75
+ | `refresh` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Function to manually refresh the data. |
76
+ | `execute` | `(opts?: AsyncDataExecuteOptions) => Promise<void>` | Alias for `refresh`. |
77
+ | `error` | `Ref<ErrorT \| undefined>` | Error object if the data fetching failed. |
78
+ | `status` | `Ref<'idle' \| 'pending' \| 'success' \| 'error'>` | Status of the data request. |
79
+ | `clear` | `() => void` | Resets `data` to `undefined`, `error` to `undefined`, sets `status` to `idle`, and cancels any pending requests. |
80
+
81
+ :read-more{to="/docs/4.x/api/composables/use-fetch#return-values"}
82
+
83
+ ## Examples
84
+
85
+ ### Handling Pending State
86
+
87
+ ```vue [app/pages/index.vue]
88
+ <script setup lang="ts">
89
+ /* Navigation will occur before fetching is complete.
90
+ * Handle 'pending' and 'error' states directly within your component's template
91
+ */
92
+ const { status, data: posts } = await useLazyFetch('/api/posts')
93
+ watch(posts, (newPosts) => {
94
+ // Because posts might start out null, you won't have access
95
+ // to its contents immediately, but you can watch it.
96
+ })
97
+ </script>
98
+
99
+ <template>
100
+ <div v-if="status === 'pending'">
101
+ Loading ...
102
+ </div>
103
+ <div v-else>
104
+ <div v-for="post in posts">
105
+ <!-- do something -->
106
+ </div>
107
+ </div>
108
+ </template>
109
+ ```
110
+
111
+ :read-more{to="/docs/4.x/getting-started/data-fetching"}