EDIT: I am on Nuxt version 3.7.1
I have a Nuxt website. I have a server endpoint to fetch content. When the page first loads, the current data shows up. If I refresh the page, useFetch is not called (based on the network log) and old data is shown. The old data seems to be the data that was there at the time of deployment. Here is the code for one of these pages:
<template>
<div>
<menu-item v-for="item in items" :title="item.title" :content="item.content" />
</div>
</template>
<script setup lang="ts">
const { data: res } = await useFetch(
"https://getcontent-***-uc.a.run.app/",
{
method: "GET",
query: {
websiteId: "***",
contentGroupId: "***",
},
}
);
const items = (res.value as any).data;
</script>
Try adding a key
value inside useFetch
's options object with an unique value every time (so for example based on Date.now()
). That's what helped me with similar issue. Otherwise useFetch
tends to cache data and won't re-fetch when it thinks it is the same API call.