Vue中自定义校验
- 初始化定义校验内容
selveRule:{
collateral_class: [
// { required: true, message: "请选择押品类别", trigger: "change" },
{ validator: validatecheckboxclass, trigger: 'change' },
],
}
- data中校验规则
//押品类别自定义校验
//value可以随时监听表单中输入对应字段的值,并且写校验规则及正则
var validatecheckboxclass = (rule, value, callback) => {
if (this.collateral_class == '' || this.collateral_class == null || this.collateral_class == undefined || this.collateral_class.length<1) {
callback(new Error('请至少选择一项'));
}else{
callback();
}
};