使用 Vuelidate Vuejs 进行自定义验证
Custom validation with Vuelidate Vuejs
我有 4 个输入,都必须是必需的( 我做了,并且有效),但第一个输入必须与接下来的 3 个字段相等, 不适用于我当前的代码。 (我在控制台中也没有错误)
import { required, minValue } from "vuelidate/lib/validators";
// ..code...
created() {
const minValue = (value) => value === this.high_confidence + this.medium_confidence + this.no_confidence;
},
validations: {
nr_of_clauses_per_round: {
required,
minValue
},
high_confidence: {
required
},
medium_confidence: {
required
},
no_confidence: {
required
}
},
您也应该从 Vuelidate 中导入 { sameAs },并像那样添加验证 sameAs([您的字段])。
我有 4 个输入,都必须是必需的( 我做了,并且有效),但第一个输入必须与接下来的 3 个字段相等, 不适用于我当前的代码。 (我在控制台中也没有错误)
import { required, minValue } from "vuelidate/lib/validators";
// ..code...
created() {
const minValue = (value) => value === this.high_confidence + this.medium_confidence + this.no_confidence;
},
validations: {
nr_of_clauses_per_round: {
required,
minValue
},
high_confidence: {
required
},
medium_confidence: {
required
},
no_confidence: {
required
}
},
您也应该从 Vuelidate 中导入 { sameAs },并像那样添加验证 sameAs([您的字段])。