【发布时间】:2020-02-14 09:01:46
【问题描述】:
我有 2 个发布请求,如果第一个被触发,第二个必须等待响应并执行发布请求。我读过一些关于 await 和 async 的东西,但不好。
let changed =false;
if(//something then){
changed = true;
axios.post('/uploadfile/' + id, // This must be first
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
}
})
.then(function(response){
// get response and do something
})
.catch(function(){
//
});
}
// if changed = true, then await for response from first post
axios.post('/uploadfile' + this.id_contract, // If
data,
{
headers: {
Authorization: getToken()
}
})
.then(function(){
// do something else
})
.catch(function(){
//
});
【问题讨论】: