在vue中循环调用接口-promise.all()
methods: {
handleAdd (arr) {
this.loading = true
const allApi = []
arr.forEach((item, index) => {
const data = {
id: item.id,
name: item.name
}
const oneApi = api.add(data).then(res => {
if (res.error_code === 0) {
this.$message.success(res.msg)
} else {
this.$message.error(res.msg)
}
})
allApi.push(oneApi)
})
Promise.all(allApi).then(() => {
this.loading = false
})
}
}
原文链接:https://blog.csdn.net/m0_46251434/article/details/114324020

浙公网安备 33010602011771号