在服务端组件中获取数据并控制缓存。

本节要点

  • 服务端组件可以直接 await 数据
  • fetch 默认带缓存
  • revalidate 控制重新验证周期

代码示例

export default async function Page() {
  const res = await fetch('https://api.example.com/posts', {
    next: { revalidate: 60 },
  });
  const posts = await res.json();
  return <ul>{posts.map((p: any) => <li key={p.id}>{p.title}</li>)}</ul>;
}
提示:需要实时数据时使用 cache: "no-store"。