Validation vee验证:仅当满足条件时才需要

Validation vee验证:仅当满足条件时才需要,validation,vue.js,vuejs2,Validation,Vue.js,Vuejs2,我正在使用Vuejs2和vee validate进行表单验证。这是一个很棒的包,但是我正在努力实现一个有条件的必填字段 当选择特定的单选选项时,我希望需要两个select字段。如果没有选择收音机,我希望两个选择字段是可选的 我尝试过使用attach和detach方法。我可以成功分离验证。当我附加一个字段时,我可以看到它出现在字段对象中。但是验证器没有检测到 这是我的密码: 公司基本信息 Lorem ipsum dolor sit amet,是一位杰出的献身者 单位 {{errors.first

我正在使用Vuejs2和vee validate进行表单验证。这是一个很棒的包,但是我正在努力实现一个有条件的必填字段

当选择特定的单选选项时,我希望需要两个select字段。如果没有选择收音机,我希望两个选择字段是可选的

我尝试过使用
attach
detach
方法。我可以成功分离验证。当我附加一个字段时,我可以看到它出现在
字段
对象中。但是验证器没有检测到

这是我的密码:


公司基本信息
Lorem ipsum dolor sit amet,是一位杰出的献身者

单位 {{errors.first('name')}

组织类型 买主 卖方 {{errors.first('organization_type_id')}

国家 {{country.text} {{errors.first('countries[])}

选择导出到的所有国家/地区

密码 {{cipher.text} {{errors.first('ciphers[]')}

选择您支持的所有密码

继续 导出默认值{ 道具:['countriesJson','ciphersJson'], 数据(){ 返回{ 名称:空, 组织类型:“2”, 国家:[], 密码:[], } }, 观察:{ 组织类型:职能(价值){ var vm=这个 如果(值='2'){ vm.$validator.attach('countries[]','required'); const select=document.getElementById('countries'); select.addEventListener('change',function()){ vm.$validator.validate('required',this.value); }); vm.$validator.attach('ciphers[]','required'); const select=document.getElementById(“密码”); select.addEventListener('change',function()){ vm.$validator.validate('required',this.value); }); }否则{ vm.$validator.detach('countries[]) vm.$validator.detach('ciphers[]) } }, }, 安装的(){ this.countries=JSON.parse(this.countriesJson) this.ciphers=JSON.parse(this.ciphersJson) }, 方法:{ 提交人:函数(e){ 这是.$validator.validateAll()。然后(成功=>{ e、 target.submit() }).catch(()=>{ 返回 }) } } }
你的意思可能是这样的吗


其中“isRequired”是计算字段,取决于条件 在我的例子中,它通过给出上述条件起作用。。在多个验证规则的情况下,它也很有用。。。e、 g.“必需的|整数|介于:18,99'


添加{}将破坏表达式

完美解决方案-我完全忘记了计算值。谢谢你的帮助。
这是错误的。您不能在这样的模板中使用
this
。在vee validate v3中,现在有
required\u if
规则: