正如标题所述,我需要在 axios 调用函数之后刷新页面,但不是在收到承诺之前。函数触发后页面当前正在刷新,但未收到承诺。我想要做的是向 api 提交一篇博客文章,当我在最后添加 preventDefault 函数时,一切正常。
这里的功能:
handleSubmit(event){
axios.post("https://saulvegablog.devcamp.space/portfolio/portfolio_blogs", this.buildForm(), {withCredentials:true})
.then(response => {
this.props.handleSuccessfullFormSubmission(response.data);
}).catch(error => {
console.log("handlesubmit error for blog ", error)
})
event.preventDefault();
}
Run Code Online (Sandbox Code Playgroud)
您可以then
通过添加在回调函数中重新加载页面
window.location.reload()
Run Code Online (Sandbox Code Playgroud)
像这样
handleSubmit(event){
event.preventDefault();
axios.post("https://saulvegablog.devcamp.space/portfolio/portfolio_blogs", this.buildForm(), {withCredentials:true})
.then(response => {
this.props.handleSuccessfullFormSubmission(response.data);
window.location.reload();
}).catch(error => {
console.log("handlesubmit error for blog ", error)
})
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4636 次 |
最近记录: |