EDIT: I am on Nuxt version 3.7.1
编辑:我使用的是Nuxt 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:
我有一个Nuxt网站。我有一个服务器端点来获取内容。当页面第一次加载时,会显示当前数据。如果我刷新页面,则不会调用useFetch(基于网络日志),并显示旧数据。旧数据似乎是部署时存在的数据。以下是其中一个页面的代码:
<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.
尝试在useFetch的选项对象中添加一个键值,每次都有一个唯一的值(例如基于Date.now())。这就是帮助我解决类似问题的方法。否则,useFetch倾向于缓存数据,并且当它认为这是同一个API调用时不会重新获取。
更多回答
我是一名优秀的程序员,十分优秀!