我是Next Js和函数式共生体的新手。我正在尝试从 /api/retrieve2 检索数据
//this is retrieve page
export default function Retrieve() {
const onSubmit = async data => {
const { user } = await axios.post("/api/retrieve2", data);
console.log(user) // user here is undefined
};
return (...);
}
//this is retrieve2, inside the API folder
export default async (req, res) => {
try {
const { data } = await axios.post(myBackendUrl, req.body);
console.log(data) //this is printing the right data - { email: 'casas@gmail.com', code: '123123' }
res.json(data);
} catch (e) {
res.json({ err: e.message || e });
}
};
我错过了什么,这是关于下一步的东西吗?关于功能组件?
小唯快跑啊
犯罪嫌疑人X
相关分类