提交表单后,如何将状态更改为空白? 提交表单后,我尝试再次清空它,但是状态仍然有价值 完成后,将状态提交回初始状态
state = {
importExcel: '',
active: true
};
handlerChange = e => {
this.setState({
importExcel: e.target.files[0],
active: !this.state.active
});
};
handlerOnSubmit = e => {
e.preventDefault()
const formData = new FormData();
formData.append('importExcel', this.state.importExcel);
api.post('web/user/import', formData)
.then(res => {
const { message, success } = res.data;
const alert = swal({
title: success === false ? 'Gagal Upload' : 'Berhasil Upload',
text: message,
icon: success === false ? 'error' : 'success',
// timer: 5000,
button: true
})
if (success === false) {
return alert
} else {
return alert
}
})
this.setState({
importExcel: '',
active: true
})
}
答案 0 :(得分:0)
if (success === false) {
return alert
} else {
return alert
}
您每次都在返回函数。因此,此行下面的代码无法执行。