Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 使用vuelidate进行动态集合验证_Vue.js_Vuelidate - Fatal编程技术网

Vue.js 使用vuelidate进行动态集合验证

Vue.js 使用vuelidate进行动态集合验证,vue.js,vuelidate,Vue.js,Vuelidate,我有一个变量项(对象数组),每个项有3个属性(值、其他和其他键),对于每个项,值字段是必需的,只有值字段值等于其他键字段时,其他字段才是必需的 看看JSFIDLE上的示例 //模板 {{$v} //Js 使用(window.vuelidate.default) const{required}=window.validators 新Vue({ el:“应用程序”, 数据:{ 项目:[{ 值:“A”, 其他:"B",, otherKey:'C' }, { 值:“D”, 其他:"E",, other

我有一个变量项(对象数组),每个项有3个属性(值、其他和其他键),对于每个项,值字段是必需的,只有值字段值等于其他键字段时,其他字段才是必需的

看看JSFIDLE上的示例

//模板
{{$v}
//Js
使用(window.vuelidate.default)
const{required}=window.validators
新Vue({
el:“应用程序”,
数据:{
项目:[{
值:“A”,
其他:"B",,
otherKey:'C'
}, {
值:“D”,
其他:"E",,
otherKey:'F'
}, {
值:“G”,
其他:'H',
另一个关键:“我很高兴。”
}]
},
验证:{
项目:{
每人$:{
值:{required},
其他:{}/{required}仅当值===otherKey时
}
}
}
})

您找到问题的解决方案了吗?
// Template
<div id="app">
   <div v-for="(item, i) in items" :key="i">
       <input type="text" v-model="item.value" 
          @input="$v.items.$each[i].$touch" 
         :class="{error: $v.items.$each[i].value.$error}">
       <input type="text" v-model="item.other" 
          @input="$v.items.$each[i].$touch" 
          :class="{error: $v.items.$each[i].other.$error}">
   </div>
   <pre>{{ $v }}</pre>
</div>

// Js
Vue.use(window.vuelidate.default)

const { required } = window.validators

new Vue({
    el: "#app",
  data: {
    items: [{
        value: 'A',
      other: 'B',
      otherKey: 'C'
    }, {
        value: 'D',
      other: 'E' ,
      otherKey: 'F'   
    }, {
        value: 'G',
      other: 'H'  ,
      otherKey: 'I'  
    }]
  },
  validations: {
    items: {
        $each: {
        value: { required },
        other: {} // { required } only if value === otherKey
      }
    }
  }
})