【发布时间】:2020-09-24 19:00:30
【问题描述】:
我有一组对象,我在表单调查问卷中循环遍历这些对象。每个对象中有五个属性,但只有一个属性需要验证。我将组件的验证部分设置如下:
specificGifts: {
$each: {
passThrough: {
required: requiredIf(function(value) {
return this.docs.includes('Will')
})
}
}
},
我在我的表单 html 中的 vuelidate 文档上看到,而不是执行以下代码:
<div
v-for="(gift, i) in specificGifts"
:key="i"
>
<v-select
label="How does this specific gift pass if the recipient does not survive?"
v-model="gift.passThrough"
:items="specificGiftPassThrough"
></v-select>
</div>
我应该使用:
<div
v-for="(gift, i) in $v.specificGifts.$each.$iter"
:key="i"
>
<v-select
label="How does this specific gift pass if the recipient does not survive?"
v-model="gift.passThrough.$model"
:items="specificGiftPassThrough"
></v-select>
</div>
我的vuejs组件的数据部分如下:
data(){
return{
specificGifts: []
}
}
但是,然后我收到以下控制台错误“无法读取未定义的属性 $model”。当我 console.log $v.specificGifts.$each.$iter 时,我也会收到控制台错误。有谁知道我做错了什么?有没有更好的方法来使用验证?看来 vuelidate 可能跟不上速度,因为它需要我对 $v 属性进行硬编码循环,以便我可以使用 vuelidate,无论如何。
【问题讨论】:
-
你发现了吗?现在刚刚遇到这个问题,想知道答案是什么。
标签: javascript vue.js vuelidate