handleAdd() { //添加检查组 var ids = this.checkitemIds; axios .post( `http://localhost:88/api/plan/checkgroup/save/${ids}`, this.formData ) .then((response) => { console.log("handleAdd:" + ids); //item的数组 console.log(response); console.log(this.formData); if (response.data.code == 0) { //如果检查组添加成功 this.dialogFormVisible = false; this.$message.success("添加成功!"); this.checkitemIds = []; this.findPage(); } }); axios.post( `http://localhost:88/api/plan/checkgroup/savegroupitem/${ids}` ); },怎么让请先执行
时间: 2024-01-19 19:02:33 浏览: 132
您可以使用Promise或async/await来确保axios.post执行完成后再执行axios.post(`http://localhost:88/api/plan/checkgroup/savegroupitem/${ids}`)。以下是使用Promise的示例代码:
```
handleAdd() {
var ids = this.checkitemIds;
axios.post(`http://localhost:88/api/plan/checkgroup/save/${ids}`, this.formData)
.then((response) => {
console.log("handleAdd:" + ids);
console.log(response);
console.log(this.formData);
if (response.data.code == 0) {
this.dialogFormVisible = false;
this.$message.success("添加成功!");
this.checkitemIds = [];
this.findPage();
return axios.post(`http://localhost:88/api/plan/checkgroup/savegroupitem/${ids}`);
}
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
});
}
```
在这个代码中,第一个axios.post返回一个Promise对象,如果response.data.code等于0,就继续执行第二个axios.post,否则不执行第二个。第二个axios.post也返回一个Promise对象,可以使用.then和.catch方法来处理它的结果。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![.zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)