7

找不到 fieldName 来验证 sameAs 方法。

相同(blabla)

blabla = 'internalFormData.password'、'internalFormData.password.value'、'this.internalFormData.password'、'this.internalFormData.password.value'、'password'、'this.password'、'password.value'

-----------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>

错误不会消失。

4

2 回答 2

5

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

validations: {
  internalFormData: {
    password: {
      required,
      minLength: minLength(8)
    },
    repassword: {
      required,
      minLength: minLength(8),
      sameAs: sameAs('internalFormData.password')
    }
  }
}
于 2019-02-17T10:15:01.767 回答
3

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

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

于 2020-03-13T14:36:50.930 回答