Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Javascript 在reactjs中提交后的Antd清除表单_Javascript_Reactjs_Antd_Ant Design Pro - Fatal编程技术网

Javascript 在reactjs中提交后的Antd清除表单

Javascript 在reactjs中提交后的Antd清除表单,javascript,reactjs,antd,ant-design-pro,Javascript,Reactjs,Antd,Ant Design Pro,我正在使用antd模板进行表单设计。提交表单后,未清除输入值 我尝试了this.props.form.resetFields()它无法工作,出现以下错误 Unhandled Rejection (TypeError): Cannot read property 'resetFields' of undefined import React,{Component,useState}来自'React'; 从“道具类型”导入道具类型; 进口{ 形式, 输入,布局, 分隔器, 工具提示, 卡斯特,

我正在使用antd模板进行表单设计。提交表单后,未清除输入值

我尝试了
this.props.form.resetFields()
它无法工作,出现以下错误

Unhandled Rejection (TypeError): Cannot read property 'resetFields' of undefined

import React,{Component,useState}来自'React';
从“道具类型”导入道具类型;
进口{
形式,
输入,布局,
分隔器,
工具提示,
卡斯特,
选择,
一行
上校,
复选框,
按钮
自动完成、输入编号、日期选择器、,
}来自‘antd’;
从“axios”导入axios;
从“react router dom”导入{withRouter};
从“力矩”中导入力矩;
从“@ant design/icons”导入{QuestionCircleOutlined};
从“./countrys.json”导入国家/地区
从“SweetAlert react”导入SweetAlert;
导入'sweetalert/dist/sweetalert.css';
const{TextArea}=输入;
const{Option}=Select;
const{Header,Content}=Layout;
常量{form}=form
类注册扩展了组件{
建造师(道具){
超级(道具);
此.state={
客户名称:“,
用户名:“”,
密码:“”,
地址:“,
国家:“,
州:“,
电邮:“,
联系人号码:空,
出生日期:“,
customerAge:null,
公民身份:“,
帐户类型:“”,
branchName:“,
初始存款金额:空,
初始化类型:“”,
initDocumentNo:“”,
州列表:[]
}
}
//处理更改文本
handleChangeText=(值、名称)=>{
this.setState({[name]:value},()=>{
如果(名称=='dob'){
此.handleChange_年龄(值)
}
})
}
handleChangeCountry=(countryName)=>{
让countrList=countries.countries;
让countryObject=countrList.find(k=>k.country==countryName);
这是我的国家({
…这个州,
状态列表:countryObject.states,
国家:countryName
})
}
//提交表格
submitForm=()=>{
const{stateList,…withoutStateList}=this.state;
axios({
方法:“post”,
网址:'http://localhost:3333/registration',
数据:无卫星列表
})。然后(响应=>{
这个.setState({
秀:真的
});
//this.props.form.resetFields();
})
}
//取消表格
导航登录=()=>{
this.props.history.push({pathname:'/login'})
}
//检查年龄和公民身份
handleChange_年龄=(出生日期)=>{
让currentAge=Math.abs((矩().year())-(矩(dob,“DD/MM/YYYY”).year());
让statusOfcitizen=null;
如果(电流小于18){
statusOfcitizen=“未成年人”;
}否则如果(当前年龄>18和当前年龄60){
statusOfcitizen=“高级”;
}
这是我的国家({
…这个州,
客户名称:currentAge,
公民身份:公民身份
})
}
render(){
常量formItemLayout={
labelCol:{
xs:{span:24},
sm:{span:9},
},
包装纸:{
xs:{span:24},
sm:{span:6},
},
};
常量tailFormItemLayout={
包装纸:{
xs:{span:24,偏移量:0,},
sm:{span:21,偏移量:0,},
},
};
函数禁用日期(当前){
返回当前和当前>时刻().endOf('day');
}
返回(
新登记
this.submitForm()}
ref={this.formRef}
>
this.handleChangeText(e.target.value,“customerName”)}/>
this.handleChangeText(e.target.value,“username”)}/>
this.handleChangeText(e.target.value,“password”)}/>
this.handleChangeText(e.target.value,“address”)}/>
这个.handleChangeCountry(e)}
过滤器选项={(输入,选项)=>
option.children.toLowerCase().indexOf(input.toLowerCase())>=0
}
>
{
countries.countries.map((cname,i)=>{
返回(
{cname.country}
)
})
}
this.handleChangeText(e,“state”)}
过滤器选项={(输入,选项)=>
option.children.toLowerCase().indexOf(input.toLowerCase())>=0
}
>
{
this.state.stateList.map((sname,i)=>{
返回(
{sname}
)
})
}
this.handleChangeText(e.target.value,“email”)}/>
this.handleChangeText(e,“contactNumber”)}
/>
此.handleChangeText(矩(e).格式(“DD/MM/YYYY”)
  formRef = React.createRef();
<Form
          {...formItemLayout}
          name="register"
          scrollToFirstError
          onFinish={() => this.submitForm()}
          ref={this.formRef}
        >
  //submit form
  submitForm = () => {
    console.log("Form submitted:", this.formRef, Form);
    this.formRef.current.resetFields();
  };
<Form key={this.state.formKey}/>
this.setState({formKey: (this.state.formKey || 0) + 1})