第一次显示此错误
我想使用Axios对我的API路由进行API调用。当我第一次运行我的代码时,它显示错误,但当我刷新 Mage 时,它工作正常。我不明白我在做什么。
import axios from "axios";
import Head from "next/head";
import Banner from "../components/Banner";
import Footer from "../components/Footer";
import HeroSection from "../components/HeroSection";
import ServicesSection from "../components/ServicesSection";
import MyWork from "../components/work/MyWork";
function Home({ workList }) {
return (
<>
<Head>
<title>EmonS - Fullstack web developer & Designer</title>
<meta
name="description"
content="This is a portfolio website which made by Jahidul Islam Emon. Here you can find work history and knowledge about Author. That is a One page application. Enjoy ."
/>
<meta
name="keywords"
content="Creative, minimal, Portfolio, business, Resume, Information, personal portfolio, Professional"
/>
<meta name="author" content="Jahidul Islam Emon"></meta>
<link rel="icon" href="/favicon.ico" />
</Head>
<HeroSection />
<ServicesSection />
<MyWork emon={workList} />
<Banner />
<Footer />
</>
);
}
export async function getServerSideProps() {
const mydomain = process.env.MY_DOMAIN;
const res = await axios.get(mydomain + "/api/work");
return {
props: {
workList: res.data,
},
};
}
export default Home;
为什么会发生这种错误?
2条答案
按热度按时间f0brbegy1#
确保在API中的dbConnect之前添加await操作符,我遇到过同样的问题,这解决了它...
因此它应该如下所示:
93ze6v8z2#
首先检查数据库服务是否联机