iles
iles copied to clipboard
Add `useFetch` and `useAsyncData` for data fetching
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?
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
.
This is all very helpful, thanks @ElMassimo !