nuxt3 usefetch仅偶尔检索数据
我与NUXT 3和何时获得数据的生命周期感到有些混淆。我了解这是一个通用的渲染过程,但是我正在使用Strapi 4来管理NUXT 3项目中的内容,并且偶尔我会通过usefetch检索数据。来自Strapi的API路线永远不会下降,所以我可能只是做错了什么。
这是我在nuxt中的vue文件:
<script setup lang="ts">
const {data: works, pending, error} = await useFetch("http://localhost:1337/api/works", {
params: {
populate: "*"
}
});
</script>
<template>
<div>
<div v-for="work in works">
... do something
</div>
</div>
</template>
我不确定页面加载时如何获取内容。当我记录返回错误时,它只是true
。但这有时只是。内容将加载一次,然后一旦我刷新页面,它就会回到错误。因此,我认为某些东西正在缓存,也许是客户端?我真的不确定下一步该怎么做。
I'm a little bit confused with Nuxt 3 and the lifecycle of when it gets data. I understand that it's a universal rendering process, but I'm using Strapi 4 to manage content in my Nuxt 3 project and only occasionally do I retrieve the data via useFetch. The API route from Strapi never goes down so I'm probably just doing something wrong.
Here is my Vue file in Nuxt:
<script setup lang="ts">
const {data: works, pending, error} = await useFetch("http://localhost:1337/api/works", {
params: {
populate: "*"
}
});
</script>
<template>
<div>
<div v-for="work in works">
... do something
</div>
</div>
</template>
I'm not sure how to get the content when the page loads. When I log the error returned, it's just true
. But it's only sometimes. The content will load once, and then as soon as I refresh the page, it goes back to having an error. So I'm thinking something is getting cached maybe client-side? I'm really not sure what to do next.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将此选项传递给usefetch:
initialcache:false
。 请参见更多Try passing this option to useFetch:
initialCache: false
. See more为什么不将Strapi模块用于NUXT3?
它处理所有这些问题。
https://strapi.nuxtjs.org/setup
Why not using Strapi module for Nuxt3?
It handles all these issues.
https://strapi.nuxtjs.org/setup