英文:
How to use NEXTJ13 data fetch axios
问题
fetch('https://...', { cache: 'no-store' });
fetch('https://...', { next: { revalidate: 10 } });
fetch('https://...'); // cache: 'force-cache' is the default
官方文档中说,上述方法使用服务器端渲染获取数据,但如何在axios中使用它呢?Next.js是否推荐fetch而不是axios?
<details>
<summary>英文:</summary>
```js
fetch('https://...', { cache: 'no-store' });
fetch('https://...', { next: { revalidate: 10 } });
fetch('https://...'); // cache: 'force-cache' is the default
In the official documentation, it says that the above method fetches data using server-side -renering, but how do I use it with axios?
Does nextjs recommend fetch over axios?
答案1
得分: 1
Axios库必须适应Next.js的新fetch方法,而Axios尚不支持Next.js的缓存和重新验证。我建议您使用fetch,因为在Next.js 13中,所有新功能都不稳定,而Axios并不是一个好的选择。
英文:
Axios library must adapt to next js new fetch methods and axios not support next js cache and revalidate yet.
I suggest you to use fetch because in next 13 all new features are not stable and axios is not a good choice for this case.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论