promise.all 主要是等所有的接口都调完,再进行下一步操作
例如,这里要等两个接口都请求回来,然后进行修改一个状态
methods里面的两个接口
// 获取仓库详情
getWarehouseDetail() {
const params = { id: this.id }
return new Promise((resolve, reject) => {
warehouseApi.warehouseManage.getById(params, (res) => {
if (res.code === '0000') {
this.warehouseDetail = res.data
resolve()
} else {
this.$message.warning({ message: res.msg })
reject()
}
})
})
},
// 获取仓库库存详情
getInventoryDetail() {
return new Promise((resolve, reject) => {
warehouseApi.inventory.queryInventory({ warehouseNo : this.warehouseNo }, (res) => {
if (res.code === '0000') {
this.isInventory = 1
const data = res.data.data
this.inventoryDetail = data && data.length && data[0] || {}
resolve()
} else {
this.$message.warning({ message: res.msg })
}
})
})
}
watch里面的操作
submitStatus (val) {
if (val) {
Promise.all([this.getWarehouseDetail(), this.getInventoryDetail()]).then(()=> {
this.$store.commit('setStore', false)
})
}
}