nuxt3 usefetch仅偶尔检索数据

发布于 2025-02-03 09:48:42 字数 630 浏览 3 评论 0原文

我与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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑咖 2025-02-10 09:48:42

尝试将此选项传递给usefetch:initialcache:false请参见更多

Try passing this option to useFetch: initialCache: false. See more

晨与橙与城 2025-02-10 09:48:42

为什么不将Strapi模块用于NUXT3?
它处理所有这些问题。
https://strapi.nuxtjs.org/setup

Why not using Strapi module for Nuxt3?
It handles all these issues.
https://strapi.nuxtjs.org/setup

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文