【发布时间】:2020-12-14 12:45:22
【问题描述】:
组合框是这样定义的:
<template>
<v-combobox
clearable
v-model="values"
:items="items"
item-text="name"
></v-combobox>
</template>
<script>
data () {
return {
items: [
{"id": 2, "name": "tree"},
{"id": 4, "name": "grass"},
{"id": 5, "name": "freeze"},
{"id": 9, "name": "moss"}
],
values: ''
},
watch: {
values () {
console.log(this.values) // Output: {__ob__: Observer}: e.g. id: 2, name: tree
}
}
}
</script>
组合框项目是可编辑的:我可以选择其中一个(然后观察者登录到控制台),然后编辑它,但控制台中没有任何反应。
如何使用已编辑的条目更新模型?
编辑:刚刚发现模型在离开组合框字段 (onBlur) 时得到更新。如何将此行为更改为例如onKeyDown?
EDIT2:另一个发现:在组合框外单击时,values 被重置(未定义)。因此,只能考虑 onChange 事件。
【问题讨论】:
标签: vue.js combobox vuetify.js