最终编辑/解决方案:https://jsfiddle.net/up9xkhsm/1/
是否存在v-select这样的事件,我可以在关闭时键入?或者某种“计时器”我可以设置为在发生验证错误后删除它们?
这是我使用的v-select
:https://vuetifyjs.com/en/components/selects
编辑:这概述了问题:https://jsfiddle.net/96vnLm7g/
我想知道用户何时点击v-select
但没有选择任何内容。显然,它必须是可能的,因为验证可以解决这个问题。
使用onChange
prop添加回调函数,这样您就可以检查分配给v-model
的v-select
(如果已更改),以清除验证错误。或者观看分配给v-model
的v-select
进行更改。
使用onChange
:
<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-select
的模型:
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()方法中使用焦点事件,告诉VueJS单击该组件,以便可以用来捕获click事件:
<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
方法