我们如何选择所有选项来选择v-select
或v-combobox
中的所有内容?
答案 0 :(得分:3)
Vuetify对Select all
没有v-select
选项。但是,您可以使用按钮和方法自行完成。
像这样:
<强> JS 强>
methods: {
selectAll(){
// Copy all v-select's items in your selectedItem array
this.yourVSelectModel = [...this.vSelectItems]
}
}
<强> HTML 强>
<v-btn @click="selectAll">Select all</v-btn>
EDIT v1.2 Vuetify添加了prepend-item
广告位,可让您在列出商品之前添加自定义商品。
可以使用前置和附加项目选择性地扩展v-select组件。这非常适合自定义全选功能。
<强> HTML 强>
<v-select
v-model="selectedFruits"
:items="fruits"
label="Favorite Fruits"
multiple
>
<!-- Add a tile with Select All as Lalbel and binded on a method that add or remove all items -->
<v-list-tile
slot="prepend-item"
ripple
@click="toggle"
>
<v-list-tile-action>
<v-icon :color="selectedFruits.length > 0 ? 'indigo darken-4' : ''">{{ icon }}</v-icon>
</v-list-tile-action>
<v-list-tile-title>Select All</v-list-tile-title>
</v-list-tile>
<v-divider
slot="prepend-item"
class="mt-2"
/>
</v-select>
<强> JS 强>
computed: {
likesAllFruit () {
return this.selectedFruits.length === this.fruits.length
},
likesSomeFruit () {
return this.selectedFruits.length > 0 && !this.likesAllFruit
},
icon () {
if (this.likesAllFruit) return 'mdi-close-box'
if (this.likesSomeFruit) return 'mdi-minus-box'
return 'mdi-checkbox-blank-outline'
}
},
methods: {
toggle () {
this.$nextTick(() => {
if (this.likesAllFruit) {
this.selectedFruits = []
} else {
this.selectedFruits = this.fruits.slice()
}
})
}
}