使用promise封装el-form多个表单校验

function() {
        let dForm = this.$refs['updateHouse'].$refs['roomForm'].$refs['dForm'];
        let dataForm = this.$refs['updateHouse'].$refs['dataForm'];
        let customForm = dForm.model;
        let form = dataForm.model;
        let validateForm = form => {
          return new Promise((resolve,reject)=>{
            form.validate(valid=>{
              if(valid) {
                resolve(valid)
              }else {
                reject(valid)
              }
            })
          })
        }
        let validateA = validateForm(dForm)
        let validateB = validateForm(dataForm)
        let p = await Promise.all([validateA,validateB]).then(res=>res).catch(e => console.log(e));
        if(!Array.isArray(p) || p.some(bool => !bool)) {
          return
        }  
}

  

posted @ 2021-07-08 16:05  你丫才美工  阅读(414)  评论(0编辑  收藏  举报