why usefetch in script setup is executed immediately and rendered on the server, but if you wrap it in a function, then ssr does not work and everything happens with a delay?
This is how everything happens as it should and quickly:
<script setup>
const { data: post } = await useFetch('https://old.webinvolga.ru/wp-json/wp/v2/cases', {
refetch: true,
method: 'GET',
lazy: true,
server: true
});
</script>
But SSR doesn’t work like that and the data is received with a delay
<script setup>
async function getPosts() {
const { data: post } = await useFetch('https://old.webinvolga.ru/wp-json/wp/v2/cases', {
refetch: true,
method: 'GET',
lazy: true,
server: true
});
}
getPosts();
</script>
I tried different methods, but didn’t find a solution.
New contributor
Romy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0