列表项目组
v-list-item-group
提供创建一组可选择的 v-list-item
的能力。v-list-item-group
组件利用其核心的 v-item-group 来为交互式列表提供一个简洁的接口。
用例
默认情况下,v-list-item-group
操作类似于 v-item-group
。如果没有提供 value ,则该群组将基于其索引提供默认值。
template script
<template>
<v-card
class="mx-auto"
max-width="500"
>
<v-list>
<v-list-item-group v-model="model">
<v-list-item
v-for="(item, i) in items"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
{
icon: 'mdi-inbox',
text: 'Inbox',
},
{
icon: 'mdi-star',
text: 'Star',
},
{
icon: 'mdi-send',
text: 'Send',
},
{
icon: 'mdi-email-open',
text: 'Drafts',
},
],
model: 1,
}),
}
</script>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<div>
<v-row justify="space-around">
<v-switch v-model="multiple" class="mx-2" label="Multiple"></v-switch>
<v-switch v-model="mandatory" class="mx-2" label="Mandatory"></v-switch>
<v-switch v-model="flat" class="mx-2" label="Flat"></v-switch>
<v-switch v-model="dense" class="mx-2" label="Dense"></v-switch>
<v-col cols="12">
<v-slider v-model="count" min="0" max="25" label="Items count"></v-slider>
</v-col>
</v-row>
<v-card
class="mx-auto"
max-width="400"
>
<v-list
:flat="flat"
:dense="dense"
>
<v-list-item-group
v-model="model"
:multiple="multiple"
:mandatory="mandatory"
color="indigo"
>
<v-list-item
v-for="i in count"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</div>
</template>
<script>
export default {
data: () => ({
item: {
icon: 'mdi-wifi',
text: 'Wifi',
},
model: 1,
multiple: false,
mandatory: false,
flat: false,
dense: false,
count: 4,
}),
}
</script>
示例
下面是一些简单到复杂的例子。
不加强调的选择
您可以轻松地禁用选定的 v-list-items 的默认高亮度。这将为用户的选择创建一个较低的配置文件。
template script
<template>
<v-card
class="mx-auto"
max-width="400"
>
<v-list flat>
<v-list-item-group v-model="model" color="indigo">
<v-list-item
v-for="(item, i) in items"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
{
icon: 'mdi-wifi',
text: 'Wifi',
},
{
icon: 'mdi-bluetooth',
text: 'Bluetooth',
},
{
icon: 'mdi-chart-donut',
text: 'Data Usage',
},
],
model: 1,
}),
}
</script>
选择多个项目
您可以一次选择多个项目。
template script
<template>
<v-card
class="mx-auto"
max-width="400"
>
<v-list>
<v-list-item-group v-model="model" multiple color="indigo">
<v-list-item
v-for="(item, i) in items"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
{
icon: 'mdi-wifi',
text: 'Wifi',
},
{
icon: 'mdi-bluetooth',
text: 'Bluetooth',
},
{
icon: 'mdi-chart-donut',
text: 'Data Usage',
},
],
model: [1],
}),
}
</script>
必填项
必须至少选定一项。
template script
<template>
<v-card
class="mx-auto"
max-width="400"
>
<v-list>
<v-list-item-group v-model="model" mandatory color="indigo">
<v-list-item
v-for="(item, i) in items"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
{
icon: 'mdi-wifi',
text: 'Wifi',
},
{
icon: 'mdi-bluetooth',
text: 'Bluetooth',
},
{
icon: 'mdi-chart-donut',
text: 'Data Usage',
},
],
model: 1,
}),
}
</script>
Alpha Theme
Complete theme experience including enhanced Vue CLI, full documentation, 5 custom components and much more!
ads by Vuetify
](https://store.vuetifyjs.com/product/alpha-theme?ref=vuetifyjs.com)
自定义活动类
您可以设置一个在选择项目时将添加的类。
template script style
<template>
<v-card
class="mx-auto"
max-width="400"
>
<v-list>
<v-list-item-group v-model="model" active-class="border" color="indigo">
<v-list-item
v-for="(item, i) in items"
:key="i"
>
<v-list-item-icon>
<v-icon v-text="item.icon"></v-icon>
</v-list-item-icon>
<v-list-item-content>
<v-list-item-title v-text="item.text"></v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
{
icon: 'mdi-wifi',
text: 'Wifi',
},
{
icon: 'mdi-bluetooth',
text: 'Bluetooth',
},
{
icon: 'mdi-chart-donut',
text: 'Data Usage',
},
],
model: 1,
}),
}
</script>
<style scoped>
.border {
border: 2px dashed orange;
}
</style>
选择控件
使用默认插槽,可以访问项的内部状态并切换它。由于 active 属性是一个 _boolean_,我们使用复选框上的 true-value 属性将其状态绑定到 v-list-item
。
template script
<template>
<v-card
class="mx-auto"
max-width="500"
>
<v-list shaped>
<v-list-item-group
v-model="model"
multiple
>
<template v-for="(item, i) in items">
<v-divider
v-if="!item"
:key="`divider-${i}`"
></v-divider>
<v-list-item
v-else
:key="`item-${i}`"
:value="item"
active-class="deep-purple--text text--accent-4"
>
<template v-slot:default="{ active, toggle }">
<v-list-item-content>
<v-list-item-title v-text="item"></v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-checkbox
:input-value="active"
:true-value="item"
color="deep-purple accent-4"
@click="toggle"
></v-checkbox>
</v-list-item-action>
</template>
</v-list-item>
</template>
</v-list-item-group>
</v-list>
</v-card>
</template>
<script>
export default {
data: () => ({
items: [
'Dog Photos',
'Cat Photos',
'',
'Potatoes',
'Carrots',
],
model: ['Carrots'],
}),
}
</script>