使用一个
onChange
属性添加回调函数,以便检查
v-model
指派给
v-select
如果已更改,则清除验证错误。或观看
V-模型
指派给
V选择
为了改变。
使用
换上
:
<v-select :options="options" :on-change="cleanUpValidation" v-model="selectModel" name="some-select"></v-select>
在VueJS
methods: {
cleanUpValidation(){
//do the cleanup
}
}
默认情况下,onchange发出
input
具有所选选项值的事件:
default: function (val) {
this.$emit('input', val)
}
因此,您还可以使用它来捕获输入事件:
<v-select :options="options" @input="cleanUpValidation" v-model="selectModel" name="some-select"></v-select>
在VueJS
methods: {
cleanUpValidation(val){
//do something with selected option value or cleanup error
}
}
或者您可以观看分配给
V选择
:
watch: {
'selectModel' : function(){
//do the cleanup or something with this.selectModel
}
}
有关onchange和其他道具,请参见:
https://sagalbot.github.io/vue-select/docs/Api/Props.html
同样的事情也适用于VuetifyJS的v-select。
编辑:
主要目标是在实际单击v-select时清除验证错误。
v-select在其onclick()方法中使用focus event,告诉Vuejs已单击组件,以便可以用于捕获单击事件:
<v-select
@input="inputChanged"
v-on:change="changeChanged"
label="Select Item"
:items="myItems"
required
:rules="rules.requiredField"
@focus="focusChanged"
>
</v-select>
在JS中:
methods:{
focusChanged(){
console.log('focusChanged ');
},
}
最后一个例子:
https://jsfiddle.net/c5moqweu/
看到
https://github.com/vuetifyjs/vuetify/blob/master/packages/vuetify/src/components/VSelect/VSelect.js
onClick
方法