更新时间:2022-06-01 05:48:54
所以,伙计们,这就是解决方案.
So, guys, here's the solution.
问题是刷新表单的时间,是在发送之前刷新.为了解决这个问题,设置在响应时刷新表单,就完成了!
The problem was the time for refreshing the form, is refreshing before send it. To solve this, set to refresh the form on response, and is done!
const handleSubmit = async event => {
event.preventDefault();
try {
await fetch(`https://api.example.net/api/route?slug=example`, {
method: 'post',
headers: {
'Content-Type': 'application/json',
'x-api-key': /* API KEY*/
},
body: JSON.stringify({
name,
email
})
})
.then(response => location.reload())
.catch(err => console.log(err));
} catch (error) {
console.log(error);
}
};