如何使用NEXTJ13数据获取axios

huangapple go评论59阅读模式
英文:

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(&#39;https://...&#39;, { cache: &#39;no-store&#39; });

fetch(&#39;https://...&#39;, { next: { revalidate: 10 } });

fetch(&#39;https://...&#39;); // cache: &#39;force-cache&#39; 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.

huangapple
  • 本文由 发表于 2023年5月11日 13:13:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76224324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定