반응형
v-select 또는 v-comobox에서 "모두 선택" 옵션을 사용하는 방법
모든 항목을 선택하기 위한 모든 선택 옵션을 어떻게 가지고 있는가?v-select
또는 av-combobox
?
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()
}
})
}
}
Code Pen with Select All prefend 항목
v-select에서 슬롯 사전 설정 및 추가에 대한 설명
v-select에 "ALL" 옵션을 추가하려면 다음과 같이 하십시오.다음과 같은 방법으로 할 수 있다.
<v-select
:items='[{text: "--ALL--", value:""}, ...myItems]'
label='Select an item'
outlined
></v-select>
반응형
'programing' 카테고리의 다른 글
최종 블록은 항상 Java에서 실행되는가? (0) | 2022.04.25 |
---|---|
C 및 C++에서 유니언의 목적 (0) | 2022.04.25 |
Axios 인터셉터 - vuex 스토어에서 응답을 반환하는 방법 (0) | 2022.04.25 |
Java에서 null 문자열을 연결 중 (0) | 2022.04.25 |
JAXB를 사용하여 XML 문자열에서 개체 생성 (0) | 2022.04.25 |