Element UI 多个Form表单同时验证

这里讲的主要是Element UI 组件的表单验证,Element UI 的Form表单验证是依靠 ref 来进行的,但是当一个页面有用到多个Form表单的时候,又要同时对这多个表单进行验证,这个时候写在后面的Form表单会覆盖前面的样式,导致只会验证最后一个

解决方案:

async submitForm(formName) {
        try {
        await Promise.all([
          this.$refs.ruleForm1.validate(),
          this.$refs.ruleForm2.validate()
        ]);
        // 验证成功
        console.log('submit');
      } catch (error) {
         // 验证失败
        console.log("error submit!!");
        return;
      }

猜你喜欢

转载自blog.csdn.net/L_yupeng/article/details/127247592
今日推荐