【发布时间】:2020-04-11 11:44:29
【问题描述】:
我有一个自定义的 veevalidate 规则,用于查看输入的值是否已经在该组件的数组中。我想在具有不同数组的不同组件中使用此规则。有没有办法做到这一点?这是我目前在一个组件中的规则
const isUnique = (value) => {
const reg = new RegExp(`^${value}$`, 'i');
const inputValue = this.myArray.filter(str => reg.test(str));
if (inputValue.length > 0) {
return {
valid: false,
data: {
message: `The ${inputValue} already exists.`,
},
};
}
return { valid: true };
};
Validator.extend('unique', {
validate: isUnique,
getMessage: (field, params, data) => data.message,
});
【问题讨论】:
标签: vue.js vee-validate