关于async:async-await实际用法

9次阅读

共计 539 个字符,预计需要花费 2 分钟才能阅读完成。

async handleSubmit() {await this.handleSubmitReport()  // 1
      await this.handleSubmitEdit()    // 2
      this.showSuccess = true          // 3
      this.showSuccessText = '你已胜利提交查看后果!'
    },

// 执行接口 1
async handleSubmitReport() {const { data} = await postAction(this.api.report, this.params.hiddenList)
  if (data.success) {return data.result} else {this.$message.error(data.message)
    this.$tip.loaded()
    return null
  }
},

// 执行接口 2
async handleSubmitEdit() {const { data} = await postAction(this.api.edit, this.dataInfo)
  if (data.success) {return data.result} else {this.$message.error(data.message)
    this.$tip.loaded()
    return null
  }
},
正文完
 0