getStaticProps 和 getServerSideProps 里面的 fetch 和原生浏览器 fetch 一样吗API?
Is fetch inside getStaticProps and getServerSideProps the same as the native browser fetch API?
我已经使用 Next.js 一段时间了,我怀疑 fetch API 在 getStaticProps
和 [=13 中使用=].
下面写下我对getStaticProps
和getServerSideProps
的理解:
getStaticProps 在构建时和 ISR 期间被调用
getServerSideProps 将在请求时被调用,但两者都无法访问客户端。
这是我对这些异步函数的理解。
所以我的疑惑是我们只写服务端代码Node.js没有原生fetchAPI,所以[=12=里面用什么fetchAPI ] 和 getServerSideProps
?是 native fetch 吗?或者一些名为 fetch?
的 polyfill
async function getStaticProps(ctx){
// Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // Some API
return {
props: {
data
}
}
}
async function getServerSideProps(ctx){
// ** Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // **Some API**
return {
props: {
data
}
}
}
真的很想知道使用了哪个 fetch API。
So my doubt is we only write server-side code and node.js doesn't have a native fetch API, so what fetch API is used inside getStaticProps and getServerSideProps?
在Node.js环境中(getStaticProps
、getServerSideProps
和API路由)Next.js使用node-fetch
到polyfill the fetch
API .
我已经使用 Next.js 一段时间了,我怀疑 fetch API 在 getStaticProps
和 [=13 中使用=].
下面写下我对getStaticProps
和getServerSideProps
的理解:
getStaticProps 在构建时和 ISR 期间被调用
getServerSideProps 将在请求时被调用,但两者都无法访问客户端。
这是我对这些异步函数的理解。
所以我的疑惑是我们只写服务端代码Node.js没有原生fetchAPI,所以[=12=里面用什么fetchAPI ] 和 getServerSideProps
?是 native fetch 吗?或者一些名为 fetch?
async function getStaticProps(ctx){
// Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // Some API
return {
props: {
data
}
}
}
async function getServerSideProps(ctx){
// ** Which fetch API is this, browser fetch or some polyfill with same name as
fetch?
const data = fetch(.../..) // **Some API**
return {
props: {
data
}
}
}
真的很想知道使用了哪个 fetch API。
So my doubt is we only write server-side code and node.js doesn't have a native fetch API, so what fetch API is used inside getStaticProps and getServerSideProps?
在Node.js环境中(getStaticProps
、getServerSideProps
和API路由)Next.js使用node-fetch
到polyfill the fetch
API .