2022-10-06 09:15:30 +00:00
---
description: This wrapper around useAsyncData triggers navigation immediately.
---
2022-04-06 05:56:08 +00:00
# `useLazyAsyncData`
2023-07-07 16:24:09 +00:00
`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` .
2022-10-06 09:15:30 +00:00
2022-04-14 10:45:53 +00:00
## Description
2022-04-14 08:53:58 +00:00
2022-11-16 10:04:28 +00:00
By default, [useAsyncData ](/docs/api/composables/use-async-data ) blocks navigation until its async handler is resolved.
2022-04-06 05:56:08 +00:00
2023-07-07 16:24:09 +00:00
> `useLazyAsyncData` has the same signature as [`useAsyncData`](/docs/api/composables/use-async-data) .
2022-04-14 10:45:53 +00:00
2022-11-16 10:04:28 +00:00
:ReadMore{link="/docs/api/composables/use-async-data"}
2022-04-06 05:56:08 +00:00
2022-04-14 08:53:58 +00:00
## Example
```vue
< template >
< div >
{{ pending ? 'Loading' : count }}
< / div >
< / template >
< script setup >
2022-04-14 10:45:53 +00:00
/* Navigation will occur before fetching is complete.
2022-04-16 13:53:36 +00:00
Handle pending and error states directly within your component's template
2022-04-14 10:45:53 +00:00
*/
2023-05-10 22:34:11 +00:00
const { pending, data: count } = await useLazyAsyncData('count', () => $fetch('/api/count'))
2022-04-14 10:45:53 +00:00
2022-04-14 08:53:58 +00:00
watch(count, (newCount) => {
2023-05-10 22:34:11 +00:00
// Because count might start out null, you won't have access
2022-04-14 08:53:58 +00:00
// to its contents immediately, but you can watch it.
})
< / script >
```
2023-02-03 11:55:58 +00:00
::alert{type=warning}
`useLazyAsyncData` is a reserved function name transformed by the compiler, so you should not name your own function `useLazyAsyncData` .
::
2022-11-16 10:04:28 +00:00
:ReadMore{link="/docs/getting-started/data-fetching#uselazyasyncdata"}