You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Next.js中fetch设置cache:'no-store'是否等效于客户端渲染?

关于Next.js中cache: 'no-store'与渲染方式的疑问

我目前正在使用Next.js,通过fetch方法获取数据,代码如下:

const res = await fetch(`${process.env.url}/test`, {
  cache: 'no-store',
})

我理解设置cache: 'no-store'会强制用户每次加载页面时重新获取数据。但这让我产生一个疑问:这个选项是否会让组件表现得更像客户端渲染?

通常执行npm run build时,Next.js会在构建阶段获取数据并生成静态HTML文件。但使用cache: 'no-store'后,数据似乎会在每次页面加载时才获取,而非构建阶段。这是否意味着我的组件本质上如同客户端渲染?希望能得到相关澄清。

附完整组件代码:

async function fetchItems() {
  const res = await fetch(`${process.env.url}/test`, {
    cache: 'no-store',
  })

  const items: Item[] = await res.json()
  return items
}

export const ItemList = async () => {
  const items = await fetchItems()
  return (
    <ul>
      {items.map((item) => (
        <li key={item.id}>
          {item.title}
        </li>
      ))}
    </ul>
  )
}

内容的提问来源于stack exchange,提问作者shinyatk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:34:57