关于async:async-await实际用法

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
  }
},

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理