[Vuejs]-Find duplicate value Vuejs

0👍

You can do something as simple as:

if(this.customer_names.indexOf(this.Pname) != -1) {
  // there is a duplicate somewhere
}

Put that code in your change/key-up event listener

0👍

You can use @blur like this:

<input
  v-model="Pname"
  type="text"
  class="form-control"
  @blur="findDuplicate"
>

function findDuplicate () {
  if(this.customer_names.indexOf(this.Pname) != -1) {
    // There is a duplicate
  }
}

So, by this when you click outside, after you are done with typing, it will run that findDuplicate function.

Leave a comment