【问题标题】:Why doesn't it work when sameAs is used in vuelidate?为什么在 vuelidate 中使用 sameAs 时它不起作用?
【发布时间】:2019-02-17 08:35:06
【问题描述】:

未找到 fieldName 来验证 sameAs 方法。

sameAs(blabla)

blabla = 'internalFormData.password', 'internalFormData.password.value', 'this.internalFormData.password', 'this.internalFormData.password.value', 'password', 'this.password', 'password.价值'

-----------script----------
data () {
  return {
     internalFormData: {
        password: '',
        repassword: ''
      }
   }
},


validations: {
      password: {
        value: {
          required,
          minLength: minLength(8)
        }
      },
      repassword: {
        value: {
          required,
          minLength: minLength(8),
          sameAs: sameAs('internalFormData.password')
        }
      }
    }
  },



---------------template--------------
<error
   v-if="!$v.internalFormData.repassword.value.sameAs"
>
  비밀번호가 일치하지 않습니다.
<error>

错误不会消失。

【问题讨论】:

    标签: vue.js vuejs2 vuelidate


    【解决方案1】:

    您的validations 结构应该反映data 中的对象,因此它应该是:

    validations: {
      internalFormData: {
        password: {
          required,
          minLength: minLength(8)
        },
        repassword: {
          required,
          minLength: minLength(8),
          sameAs: sameAs('internalFormData.password')
        }
      }
    }
    

    【讨论】:

      【解决方案2】:

      你需要用函数指出你的嵌套属性。 像这样:

      data(){return {
       password :{
        new: '',
        newRepeated:''
       }
      }},    
      validations : {
       password: {
        new : {required},
        newRepeated : {
         required,
         sameAs : sameAs( function(){return this.password.new} )
        }
       }
      }
      

      我还建议您看看这个已关闭的问题。 https://github.com/vuelidate/vuelidate/issues/252

      【讨论】:

        猜你喜欢
        • 2017-11-28
        • 1970-01-01
        • 2020-09-07
        • 2017-11-07
        • 2020-03-28
        • 1970-01-01
        • 2010-11-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多