[Vuejs]-How To Create Checking Method To Check The User Input Is Match With The ID provided?

0๐Ÿ‘

โœ…

I am not sure why you are splitting the input text. Do you allow user to enter more than one ID per input? In any case you can check for an input data this way:

new Vue({
  el: "#app",
  data() {
    return {
      selected: [],
      text: '',
      purchase_ids: [24149, 24223, 24251, 24253]
    }
  },
  methods: {
    checkInput() {
      if (this.purchase_ids.indexOf(parseInt(this.text)) > -1)
        console.log(`ID ${this.text} exists`);
      else
        console.log(`ID does not exists`);
    }
  }
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id='app'>
  <input type="text" name="test" v-model="text" placeholder="type here" />
  <button @click="checkInput()" small color="rgba(10,0,0,0)">click</button><br>
</div>

Leave a comment