我在 NEXT JS 中使用 getServerSideProps 函数进行 fetch 时遇到问题。当我开始使用这个框架时,我可能做得不好。访问外部 API 的所有凭据都是正确的。当我在 React 中使用相同的参数进行获取时,它会为我带来信息,但是使用 Next JS 它会返回 400 - 错误请求。
\n我将所有参数放在下面同一个块代码中,以便于理解。我使用像“”这样的凭据参数来保护隐私。他们是正确的,没有任何问题。
\n注意:我相信我一定以错误的方式使用了 getServerSideProps 函数。我不知道除了编写函数之外是否还需要对 Next JS 进行任何配置。换句话说,这里显示的是我到目前为止实际写的内容。该程序直接从index.js 调用。
\n这是文件夹结构:
\n\nListOrders 是我渲染页面的地方。它从我执行提取操作的 getServerSideProps 函数接收 {orders} 作为 props。
\nconst ListOrders = ({ orders }) => {\n // Render orders through server side rendering (SSR)\n return (\n <div>\n {/* If orders is an object than map over it to render the page, otherwise orders is an error message …Run Code Online (Sandbox Code Playgroud)