使用NextJS中的GetServersideProps获取更新的数据

发布于 2025-02-10 20:05:25 字数 699 浏览 0 评论 0原文

因此,我有一个公共页面,我在NextJ中使用getServersideProps进行了预先渲染。现在,一旦我对页面中的数据进行了更新,直到我重新构建之前,新的更新才显示。请如何处理?

例如,假设我有一个博客文章页面:“ https://example.com/blog/what-is-stackoverflow”。在此页面中,我通过对数据库进行API调用来获取一些图片。现在,我已经通过另一个API从2到3更新了图片的数量。 在再次访问该特定博客页面时,我只看到2张图片,而不是最新更新中的3张图片。但是,如果我重建下一个JS网站,我现在可以看到这3张图片。

这是代码的副本:

export const getServerSideProps = async ({ params }) => {
  const { data: professionalData } = await client.query({
    query: GET_PROFESSIONAL,
    variables: {
      uuid: params.uuid,
    },
  });

  return {
    props: {
      data: professionalData.user,
    },
  };
};

谢谢你等待回复

So, I have a public page which I am pre-rendering using getServerSideProps in Nextjs. Now, once I make updates to the data in the page, the new updates do not show until I re-build. Please how do I handle this?

As an example, let's say I have a blog post page: "https://example.com/blog/what-is-stackoverflow". In this page I am fetching some pictures by making an api call to a database. I have now updated the number of pictures through another api from let's say 2 to 3.
On visiting that particular blog page again, I am only seeing 2 pictures instead of 3 from the most recent update. But if I rebuild my next-js website, I now get to see the 3 pictures.

Here is a copy of the code:

export const getServerSideProps = async ({ params }) => {
  const { data: professionalData } = await client.query({
    query: GET_PROFESSIONAL,
    variables: {
      uuid: params.uuid,
    },
  });

  return {
    props: {
      data: professionalData.user,
    },
  };
};

Thank you as I await a response

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文