我的应用程序中有一个提要组件,用于从 API 端点获取数据。当我在本地构建上测试该组件时,该组件工作正常,但当我将其部署在 Vercel 上时,它无法获取最新数据。我怀疑这个问题与缓存有关。为了解决这个问题,我在 fetch 请求中添加了 cache: 'no-store' 选项,但似乎并没有解决问题。我将不胜感激任何解决此问题的帮助或建议。
"use client";
const fetchPosts = async () => {
const response = await fetch("/api/prompt", {
cache: 'no-store',
});
const data = await response.json();
setAllPosts(data);
};
useEffect(() => {
fetchPosts();
}, []);
Run Code Online (Sandbox Code Playgroud)
GitHub 链接: https://github.com/justinwkUKM/promptify/blob/main/components/Feed.jsx
注意:请针对在 Vercel 上部署时的缓存问题提供任何建议或解决方案。谢谢你!