【发布时间】:2020-01-16 11:50:16
【问题描述】:
我想在 react 中发送带有表单的电子邮件并将正文发送到节点我使用 axios.post 这是我的代码:
handleSubmit = async e => {
e.preventDefault();
const { name, number, email, message } = this.state;
await axios.post("/send", { name, number, email, message });
console.log(this.state);
};
错误信息是:
POST http://localhost:3000/send 404 (Not Found)
createError.js:17 Uncaught (in promise) Error: Request failed with status code 404
不知道为什么
【问题讨论】:
-
"/send"指向您的前端服务器,而不是后端服务器 -
我必须做什么
-
您需要发布到后端的完整 URL 而不是相对路径,或者在配置对象中传递
baseURL属性(.post()的第三个参数)