【发布时间】:2021-05-24 13:56:41
【问题描述】:
在下面的代码中,我使用了一个 v-autocomplete 组件
和一个变量select,其中存储了选定的值。
watch 记录select 的值和类型。
我面临的问题是,当清除 v-autocomplete 中键入的文本时,select 默认为 null 而不是空字符串。
有没有办法将select 还原为空字符串而不是空对象?
<div id="app">
<v-app id="inspire">
<v-card>
<v-container fluid>
<v-row
align="center"
>
<v-col cols="12">
<v-autocomplete
v-model="select"
:items="items"
dense
filled
label="Filled"
clearable
></v-autocomplete>
</v-col>
</v-row>
</v-container>
</v-card>
</v-app>
</div>
new Vue({
el: '#app',
vuetify: new Vuetify(),
data: () => ({
items: ['foo', 'bar', 'fizz', 'buzz'],
select: "",
}),
watch:{
value:function(value){
console.log(this.select) // select value
console.log(typeof(this.value)); // select variable type
}
}
})
【问题讨论】:
标签: javascript vue.js vuetify.js v-autocomplete