【发布时间】:2021-01-20 05:14:21
【问题描述】:
您好,我已将 nodejs 后端集成到 reactjs 前端。我已经做到了这些方式。但它显示错误。我是新手,请帮忙。
function Register() {
const [data, setData] = useState({
name: "",
phone: "",
password: "",
confirmpassword: "",
});
const InputEvent = (event) => {
const { name, value } = event.target;
setData((preVal) => {
return {
...preVal,
[name]: value,
};
});
};
const formSubmit = (e) => {
e.preventDefault();
const registered = {
name: "data.name",
phone: "data.phone",
password: "data.password",
};
const isValid = formValidation();
if (isValid) {
//if form is valid, route
axios
.post(`https://localhost:5000/api/v1/auth/register/`, registered)
.then((res) => {
console.log(res);
console.log(res.data);
})
.catch((err) => {
console.log(err);
});
history.push("/myvehicles" );
}
};
return (
<div className="signup__container">
<form className="register__form" onSubmit={formSubmit}>
<h5 className="h5__form"> Name</h5>
<input
type="text"
placeholder="पुरा नाम लेख्नुहोस्"
name="name"
value={data.name}
onChange={InputEvent}
/>
);
})}
<h5 className="h5__form"> phone </h5>
<input
type="text"
placeholder="फोन लेख्नुहोस्"
name="phone"
value={data.phone}
onChange={InputEvent}
/>
);
})}
<h5 className="h5__form"> Password </h5>
<input
type="Password"
placeholder="पासवर्ड लेख्नुहोस्s"
name="password"
value={data.password}
onChange={InputEvent}
/>
);
})}
<h5 className="h5__form"> Confirm Password </h5>
<input
type="Password"
placeholder="पुन: पासवर्ड लेख्नुहोस्"
name="confirmpassword"
value={data.confirmpassword}
onChange={InputEvent}
/>
);
})}
<p>
<button type="submit" className="signup__registerButton">
Register Now
</button>
</p>
</form>
</div>
);
}
export default Register;
当我同时运行后端和前端服务器并从 UI 发布值时,代码如上。它给出了错误。错误来自发布功能。如果我做错了请纠正。
【问题讨论】:
-
“它给出错误”什么错误?
-
您可以删除双引号,因为您在 url 中传递了错误的参数和 http 而不是 https。 const 注册 = { name: data.name, phone: data.phone, password: data.password };
-
在您的网址中尝试使用 http 而不是 https
-
有3个错误!它们是: 警告:失败的道具类型:道具
to在Link中标记为必填项,但其值为undefined。警告:在 -
如果我使用 http,它会给出这个错误:xhr.js:177 POST localhost:5000/api/v1/auth/register400(错误请求)错误:请求失败,状态码为 400 register.js at createError (createError.js:16 ) 在 XMLHttpRequest.handleLoad (xhr.js:62) 处解决 (settle.js:17)
标签: node.js reactjs integration webapi