Vue js vee validate password confirmation always false

前端 未结 2 1464
南方客
南方客 2021-02-05 06:22

I\'m trying to use vee validate to verify the password using this code.

2条回答
  •  梦如初夏
    2021-02-05 06:56

    Your password input must have ref="password" - that's how vee-validate finds the target:

    (Thanks, Ryley).

    confirmed:{target} - Input must have the same value as the target input, specified by {target} as the target field’s name.

    Also, there's an error with your Vee Validate syntax, change target: to confirmed:

    v-validate="'required|target:password'"

    should be

    v-validate="'required|confirmed:password'"

    Have a look at the basic example below, it will check for two things:

    • Does the second input field have any input value?
    • If yes, does the second input value match the first input value?

    var app = new Vue({
      el: '#app',
      data: {
        message: 'Hello Vue!'
      }
    })
    body {
      background: #20262E;
      padding: 15px;
      font-family: Helvetica;
    }
    
    #app {
      width: 60%;
      background: #fff;
      border-radius: 10px;
      padding: 15px;
      margin: auto;
    }
    
    
    
    
    
    
    {{ errors.first('password') }}
    {{ errors.first('password_confirmation') }}

    Further reading: https://baianat.github.io/vee-validate/guide/rules.html#confirmed

提交回复
热议问题