写自定义验证时,除需要Form中的ref、rules、model和FormItem中的prop数据结构的高度对应外,还要注意,在绑定model中的对应prop之前,还需要清理ref中的fields。否则通过validator校验的第二个参数value是不会更新的。
validator写法:
{ validator: (rule, value, callback)=>{
console.info(value);
if(value.info && value.info.isOverflow){
return callback(new Error('内存溢出'));
}
callback();
}, trigger: 'change' },
全局清理表单
this.$refs.propertiesForm.fields.forEach( (e) =>{
e.resetField();
});
或
this.$refs['propertiesForm'].resetFields(); //手动校验前须重置下表单状态。
如果只清理一个表单字段的校验,可如此写:
let isOverflowValidField = this.$refs.propertiesForm.fields.find( (e) =>{
return e.prop == 'isOverflow';
});
isOverflowValidField.resetField();