The use promise.all

promise.all prevailingly all interfaces it done, then the next step
, for example, where two interfaces are requested to wait back and modify a state of
two methods inside interfaces

// 获取仓库详情
      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 })
            }
          })
        })
      }

Inside the watch operation

   submitStatus (val) {
        if (val) {
          Promise.all([this.getWarehouseDetail(), this.getInventoryDetail()]).then(()=> {
            this.$store.commit('setStore', false)
          })
        }
      }

Guess you like

Origin www.cnblogs.com/antyhouse/p/12169234.html