Ashtav
Ashtav

Reputation: 2966

How to use onchange event on selectize in vuejs?

I use selectize as select option in vue, but I can not trigger onchange event on selectize, how I can do it? this is my code

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

and in vue methods this is my code,

test(){
   alert("it's work");
}

thank you so much for your help

Upvotes: 1

Views: 2019

Answers (3)

Cong Nguyen
Cong Nguyen

Reputation: 3455

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

Upvotes: 0

Eugene P.
Eugene P.

Reputation: 1833

@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");
}

Upvotes: 0

wang eason
wang eason

Reputation: 176

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>

Upvotes: 0

Related Questions