if中如何使用async/await?

背景:vue框架,使用element-ui的表单,并且在提交时验证

onSubmit(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
        // submitForm() 就是上传表单的接口,请问这里如果不用.then(),我想直接写async/await该怎么办
          this._submitForm().then(() => {
            if (this.subCode == 200) {
              this.$message({
                message: this.subMsg,
                type: 'success',
                center: true
              })
            } else {
              this.$message({
                message: this.subMsg,
                type: 'error',
                center: true
              })
            }
          })
        } else {
          console.log('错误提交')
        }
      })
    }


大怪i
浏览 4889回答 2
2回答

bangzss

this.$refs[form].validate( async (valid) => {        if (valid) {           await this._submitForm() 

橋本奈奈未

async onSubmit(form) {  // ...  await this._submitForm();  if(this.subCode == 200) {      // ...  }  // ... }
打开App,查看更多内容
随时随地看视频慕课网APP