Nuxt/docs/content/3.api/1.composables/use-lazy-async-data.md
Ada J 48d886c860
docs(api): document useError , useLazyAsyncData and useLazyFetch (#4341)
* docs: add documents for use-error,use-lazy-async-data and use-lazy-fetch

* docs(API): document useError,useLazyAsyncData and useLazyFetch

Co-authored-by: xiaojie.jiang <xiaojie.jiang@dhc.com.cn>
2022-04-14 10:53:58 +02:00

819 B

useLazyAsyncData

This composable behaves identically to useAsyncData with the lazy: true option set.

Otherwise, this function does not block navigation. That means you will need to handle the situation where the data is null (or whatever value you have provided in a custom default factory function).

::ReadMore{link="/api/composables/use-async-data"} ::

Example

<template>
  <div>
    {{ pending ? 'Loading' : count }}
  </div>
</template>

<script setup>
const { pending, data: count } = useLazyAsyncData('count', () => $fetch('/api/count'))
watch(count, (newCount) => {
  // Because count starts out null, you won't have access
  // to its contents immediately, but you can watch it.
})
</script>

::ReadMore{link="/guide/features/data-fetching"} ::