el-form实现其中一个填写即可的校验

el-form实现其中一个填写即可的校验_第1张图片 el-form实现其中一个填写即可的校验_第2张图片

 

      
        
          
            
              
            
          

          
            
              
            
          

          
            
              
            
          

          
            
              
                
              
            
          

          
            
              
            
          

          
            
              
            
          

          
            
              
                
              
            
          

          
            
              
            
          

          
            
              
            
          

          
            
              
            
          

          
            
              
            
          
        
      

  data() {
    return {
        formData: {},
 formRules: {
        driverName: [
          { required: true, message: "请输入司机姓名", trigger: "blur" },
        ],
        deptId: [
          { required: true, message: "请选择归属部门", trigger: "blur" },
        ],
        cardId: [
          {
            required: true,
            validator: this.validateAtLeastOneRequired,
            trigger: "blur",
          },
        ],
        printCode: [
          {
            required: true,
            validator: this.validateAtLeastOneRequired,
            trigger: "blur",
          },
        ],
        faceCode: [
          {
            required: true,
            validator: this.validateAtLeastOneRequired,
            trigger: "blur",
          },
        ],
      },
    }
 }

methods:{

    /**
     * @Event 方法
     * @description: ic卡号 指纹编号 人脸编号 其中一个必填校验
     * */
    validateAtLeastOneRequired(rule, value, callback) {
      const field = "ic卡号、指纹编号、人脸编号";
      if (
        this.formData.cardId ||
        this.formData.printCode ||
        this.formData.faceCode
      ) {
        callback();
      } else {
        callback(new Error(`${field}至少填写一个`));
      }
    },


    submitForm() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // do something
        } else {
          return false;
        }
      });
    },
}

你可能感兴趣的:(后台管理系统,vue.js,elementui,前端)