iles icon indicating copy to clipboard operation
iles copied to clipboard

Add `useFetch` and `useAsyncData` for data fetching

Open MichaelPrecel opened this issue 3 years ago • 2 comments

Thanks so much for this really interesting project!

I was wondering whether there is any way built into Iles that allows fetching data on the server at build time to be used in components? Similar to Nuxt's asyncData?

MichaelPrecel avatar Dec 02 '21 06:12 MichaelPrecel

Hi Michael!

Currently there's no built-in way, but there are several ways to achieve it.

In îles you can use await in script setup or in getStaticPaths.

See:

  • https://github.com/ElMassimo/iles/discussions/46
  • https://github.com/ElMassimo/iles/discussions/41

I'll keep this open as a reminder to automatically inject $fetch with ohmyfetch if it's used.

In the meantime you could ponyfill fetch or use ohmyfetch directly.

If you need caching, check this example using a caching utility, which ensures the request is made only once across rendered pages. Something like this might be built-in in the future, as useFetch and useAsyncData.

ElMassimo avatar Dec 02 '21 11:12 ElMassimo

This is all very helpful, thanks @ElMassimo !

MichaelPrecel avatar Dec 03 '21 07:12 MichaelPrecel