在下面的代码中,我使用了一个 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
}
}
})