use*_*413 5 javascript vue.js vuetify.js
我正在使用 vuetify 的 v-select 组件。我正在尝试在下拉列表中添加搜索栏选项。
有什么内置的方法可以做到这一点吗?我使用的是 vuetify 版本 1.0.5。
<v-select
:items="users"
attach
item-text='name'
item-value='name'
v-model="association.name"
:rules='nameRule'
label="First Name"
required>
</v-select>
Run Code Online (Sandbox Code Playgroud)
您需要添加模板槽并编写自定义搜索逻辑。我为此创建了一支代码笔。请根据您的需要进行更改。
<template v-slot:prepend-item>
<v-list-item>
<v-list-item-content>
<v-text-field v-model="searchTerm" placeholder="Search" @input="searchFruits"></v-text-field>
</v-list-item-content>
</v-list-item>
<v-divider class="mt-2"></v-divider>
</template>
// method
searchFruits (e) {
if (!this.searchTerm) {
this.fruits = this.fruitsCopy;
}
this.fruits = this.fruitsCopy.filter(fruit => {
return fruit.toLowerCase().indexOf(this.searchTerm.toLowerCase()) > -1
})
}
Run Code Online (Sandbox Code Playgroud)
https://codepen.io/sudheer-ranga/pen/bGVbjbx