为了账号安全,请及时绑定邮箱和手机立即绑定

if中如何使用async/await?

if中如何使用async/await?

大怪i 2020-01-13 17:31:18
背景: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('错误提交')         }       })     }
查看完整描述

2 回答

?
bangzss

TA贡献1条经验 获得超1个赞

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

查看完整回答
1 反对 回复 2020-10-09
?
橋本奈奈未

TA贡献436条经验 获得超108个赞


async onSubmit(form) {
 // ...
 await this._submitForm();
 if(this.subCode == 200) {
     // ...
 }
 // ...
}


查看完整回答
反对 回复 2020-01-13
  • 2 回答
  • 0 关注
  • 4859 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信