vuejs2 - 如何在 v-select 或 v-combobox 上有“全选”选项?
问题描述
我们如何有一个全选选项来选择 av-select
或 a中的所有内容v-combobox
?
解决方案
VuetifySelect 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()
}
})
}
}
推荐阅读
- python - 3d表面matplotlib上的自定义轮廓线
- node.js - Firebase Auth 有没有办法确保 displayName 在所有用户之间都是唯一的?
- azure-machine-learning-studio - 使用 log 或 parent.log() 的 azure ml 指标?
- sql - 如何在 Knex Where 子句中使用变量?
- intellij-idea - IntelliJ:如何更改参数信息弹出窗口的颜色
- python - 如何访问同一个 Docker 容器中的其他文件?
- apache-spark - 使用 Pandas UDF 进行 Pyspark 流式传输
- ionic-framework - UPI 与 ionic 应用程序的集成没有通过
- javascript - 如何将 HEIC/HEIF 图像转换为 ReactJs 中的图像
- javascript - 用玩笑测试 setTimeout 上的毫秒参数