您可以使用应用程序路由器的重新验证功能或缓存选项来完成此操作。以下是您可以尝试的两种方法:
使用重新验证:
{
const res = await fetch('/api/admin',
{ next: { revalidate: 10 }} //here you can change the time, I put 10 seconds
)
if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
}
return res.json()
}
使用缓存选项:
{
const res = await fetch('/api/admin',
{ cache: 'no-store' } //this way you will receive new data at every reload of your page
)
if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error('Failed to fetch data')
}
return res.json()
}