Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何修复react寄存器上出现以下错误的错误_Reactjs - Fatal编程技术网

Reactjs 如何修复react寄存器上出现以下错误的错误

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函数失败并给我一些错误

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';
 }