[Vuejs]-How to use onchange event on selectize in vuejs?

0πŸ‘

βœ…

You can use Watchers in vue to trigger value change:

watch: {
  'input.city': function(value) {
    console.log('city changed');
  }
}

More detail: https://v2.vuejs.org/v2/guide/computed.html#Watchers

πŸ‘€Cong Nguyen

0πŸ‘

I do not know if you used vue2-selectize, if yes, you can try code below, as this vue component emits an input event while changing selection:

<selectize v-model="input.city" data-placeholder="City" required @input="test">
   <option :value="data.id" v-for="(d, i) in cities" :key="i"> {{d.name}} </option>
</selectize>
πŸ‘€wang eason

0πŸ‘

@input works for me.

<selectize data-placeholder="City" required @input="test">
   <option :value="data.id" v-for="(d, i) in cities" :key="i"> {{d.name}} </option>
</selectize>
test(value){
   this.input.city = value;
   alert("it's work");
}
πŸ‘€Eugene P.

Leave a comment