如何在 vuejs 中的 selectize 上使用 onchange 事件?

How to use onchange event on selectize in vuejs?

我在 vue 中使用 selectize 作为 select 选项,但我无法在 selectize 上触发 onchange 事件,我该怎么做?这是我的代码

<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>

在 vue 方法中,这是我的代码,

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

非常感谢您的帮助

可以在vue中使用Watchers来触发值变化:

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

更多详情:https://vuejs.org/v2/guide/computed.html#Watchers

不知道你有没有用过vue2-selectize,如果有,你可以试试下面的代码,因为这个vue组件在改变选择时会发出一个输入事件:

<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>

@input 适合我。

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