小编use*_*024的帖子

使用 NextJS 在 Vercel 上重新验证不起作用

我使用 Vercel 文档中提供的示例,每 15 秒从 MongoDB 获取一次数据,但不幸的是该函数不起作用。我应该怎么做才能使其按预期工作?

export async function getStaticProps() {
  const allData = getSortedData();

  const client = await clientPromise;
  const isConnected = await client.isConnected();
  const alerts = await client.db()
    .collection("alerts")
    .find({})
    .limit(6)
    .toArray();
  const alertsData = JSON.parse(JSON.stringify(alerts));

  return {
    props: {
      allData,
      isConnected,
      alertsData
    },
    revalidate: 15,
  };
}
Run Code Online (Sandbox Code Playgroud)

mongodb reactjs next.js vercel getstaticprops

8
推荐指数
1
解决办法
3833
查看次数

标签 统计

getstaticprops ×1

mongodb ×1

next.js ×1

reactjs ×1

vercel ×1