Reactjs 如何修复react寄存器上出现以下错误的错误
为什么这个onSubmit函数失败并给我一些错误Reactjs 如何修复react寄存器上出现以下错误的错误,reactjs,Reactjs,为什么这个onSubmit函数失败并给我一些错误 onSubmit(e){ e、 预防默认值(); 恒定运动={ 名称:this.state.name, othername:this.state.othername, 姓:this.state.姓氏, 电子邮件:this.state.email, 日期:this.state.date, 密码:this.state.password, } 控制台日志(练习); 轴心柱http://localhost:5000/exercises/add",练习)
onSubmit(e){
e、 预防默认值();
恒定运动={
名称:this.state.name,
othername:this.state.othername,
姓:this.state.姓氏,
电子邮件:this.state.email,
日期:this.state.date,
密码:this.state.password,
}
控制台日志(练习);
轴心柱http://localhost:5000/exercises/add",练习)
。然后(res=>console.log(res.data));
window.Location='/Profile';
}
欢迎来到SO。您是否可以将错误添加到您的问题中。
constructor(props){
super()
this.state = {
name: '',
othername: '',
surname: '',
email:'',
date: '',
password: ''
}
}
handleFieldChange = function(event){
const { name, value } = event.target;
this.setState({
[name]: value
})
}
onSubmit(e){
e.preventDefault();
if(this.state.name == '' || this.state.othername == '' ||
this.state.surname == '')
{
alert('All required fields')
return false;
}
const exercise={
name: this.state.name,
othername:this.state.othername,
surname: this.state.surname,
email: this.state.email,
date: this.state.date,
password: this.state.password,
}
console.log(exercise);
axios.post('http://localhost:5000/exercises/add', exercise)
.then(res => console.log(res.data));
window.Location= '/Profile';
}