分割线
v-divider
组件用于分隔列表或布局的各个部分。
用例
最简单的分隔线显示一条水平线。
template
<template>
<v-divider></v-divider>
</template>
API
从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。
实战场
template script
<template>
<div class="grey lighten-5 pa-4">
<v-toolbar
v-if="variant === 'vertical'"
color="gray"
>
<v-toolbar-title>Title</v-toolbar-title>
<v-divider
class="mx-4"
:inset="inset"
vertical
></v-divider>
<v-spacer></v-spacer>
<v-toolbar-items>
<v-btn text>
News
</v-btn>
<v-divider :inset="inset" vertical></v-divider>
<v-btn text>
Blog
</v-btn>
<v-divider :inset="inset" vertical></v-divider>
<v-btn text>
Music
</v-btn>
<v-divider :inset="inset" vertical></v-divider>
</v-toolbar-items>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
</v-toolbar>
<v-row v-else>
<v-col cols="12" sm="6" offset-sm="3">
<v-card>
<v-list>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-inbox-arrow-down</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-inbox-arrow-down</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-inbox-arrow-down</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider :inset="inset"></v-divider>
<v-subheader>Subheader</v-subheader>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-folder</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider :inset="inset"></v-divider>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-folder</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider :inset="inset"></v-divider>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-folder</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>I'm a list item</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
</v-card>
</v-col>
</v-row>
<v-row
class="mt-12"
align="center"
justify="center"
>
<v-col
cols="12"
md="8"
>
<v-select
v-model="variant"
:items="items"
clearable
label="Variant"
light
></v-select>
<template>
<v-checkbox
v-model="inset"
hide-details
label="Inset"
light
></v-checkbox>
</template>
</v-col>
</v-row>
</div>
</template>
<script>
export default {
data: () => ({
inset: false,
items: [
'default',
'vertical',
],
variant: 'default',
}),
}
</script>
示例
下面是一些简单到复杂的例子。
嵌入式分隔线
嵌入式分隔线向右移动 72px。 这将使他们与列表项对齐。
template script
<template>
<v-row>
<v-col cols="12" sm="6" offset-sm="3">
<v-card>
<v-list two-line>
<template v-for="(item, index) in items.slice(0, 6)">
<v-subheader v-if="item.header" :key="item.header">{{ item.header }}</v-subheader>
<v-divider v-else-if="item.divider" :key="index" :inset="item.inset"></v-divider>
<v-list-item v-else :key="item.title" @click="">
<v-list-item-avatar>
<img :src="item.avatar">
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-html="item.title"></v-list-item-title>
<v-list-item-subtitle v-html="item.subtitle"></v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
</v-list>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
data: () => ({
items: [
{ header: 'Today' },
{ avatar: 'https://cdn.vuetifyjs.com/images/lists/1.jpg', title: 'Brunch this weekend?', subtitle: "<span class='font-weight-bold'>Ali Connors</span> — I'll be in your neighborhood doing errands this weekend. Do you want to hang out?" },
{ divider: true, inset: true },
{ avatar: 'https://cdn.vuetifyjs.com/images/lists/2.jpg', title: 'Summer BBQ <span class="grey--text text--lighten-1">4</span>', subtitle: "<span class='font-weight-bold'>to Alex, Scott, Jennifer</span> — Wish I could come, but I'm out of town this weekend." },
{ divider: true, inset: true },
{ avatar: 'https://cdn.vuetifyjs.com/images/lists/3.jpg', title: 'Oui oui', subtitle: "<span class='font-weight-bold'>Sandra Adams</span> — Do you have Paris recommendations? Have you ever been?" },
],
}),
}
</script>
垂直分割线
垂直分隔线为您提供了更多用于独特布局的工具。
template
<template>
<v-toolbar
color="purple"
dark
>
<v-toolbar-title>Title</v-toolbar-title>
<v-divider
class="mx-4"
vertical
></v-divider>
<span class="subheading">My Home</span>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-sm-and-down">
<v-btn text>
News
</v-btn>
<v-divider vertical></v-divider>
<v-btn text>
Blog
</v-btn>
<v-divider vertical></v-divider>
<v-btn text>
Music
</v-btn>
<v-divider vertical></v-divider>
</v-toolbar-items>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
</v-toolbar>
</template>
垂直的嵌入式分割线
垂直分割线还可以与 inset
属性一起使用,以获得更多选项。
template
<template>
<v-toolbar
color="teal"
dark
>
<v-toolbar-title>Title</v-toolbar-title>
<v-divider
class="mx-4"
inset
vertical
></v-divider>
<span class="subheading">My Home</span>
<v-spacer></v-spacer>
<v-toolbar-items class="hidden-sm-and-down">
<v-btn text>
News
</v-btn>
<v-divider
inset
vertical
></v-divider>
<v-btn text>
Blog
</v-btn>
<v-divider
inset
vertical
></v-divider>
<v-btn text>
Music
</v-btn>
<v-divider
inset
vertical
></v-divider>
</v-toolbar-items>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
</v-toolbar>
</template>
Vuetify Epic Backpack
The Vuetify Epic Backpack is a premium backpack that has a spot for everything you travel with.
ads by Vuetify
](https://store.vuetifyjs.com/product/vuetify-epic-backpack?ref=vuetifyjs.com)
分隔线和副标题
分割线和副标题可以帮助分解内容,并可以使用相同的 inset
属性来相互对齐。
template script
<template>
<v-row justify="center">
<v-col cols="12" sm="8" md="6">
<v-card>
<v-toolbar color="orange lighten-1" dark>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-toolbar-title>Message Board</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn icon>
<v-icon>mdi-magnify</v-icon>
</v-btn>
</v-toolbar>
<v-list two-line>
<template v-for="(item, index) in items">
<v-subheader
v-if="item.header"
:key="item.header"
inset
>
{{ item.header }}
</v-subheader>
<v-divider
v-else-if="item.divider"
:key="index"
inset
></v-divider>
<v-list-item
v-else
:key="item.title"
ripple
@click=""
>
<v-list-item-avatar>
<img :src="item.avatar">
</v-list-item-avatar>
<v-list-item-content>
<v-list-item-title v-html="item.title"></v-list-item-title>
<v-list-item-subtitle v-html="item.subtitle"></v-list-item-subtitle>
</v-list-item-content>
</v-list-item>
</template>
</v-list>
</v-card>
</v-col>
</v-row>
</template>
<script>
export default {
data () {
return {
items: [
{
header: 'Today',
},
{ divider: true },
{
avatar: 'https://picsum.photos/250/300?image=660',
title: 'Meeting @ Noon',
subtitle:
"<span class='font-weight-bold'>Spike Lee</span> — I'll be in your neighborhood",
},
{
avatar: 'https://picsum.photos/250/300?image=821',
title: 'Summer BBQ <span class="grey--text text--lighten-1"></span>',
subtitle:
"<span class='font-weight-bold'>to Operations support</span> — Wish I could come.",
},
{
avatar: 'https://picsum.photos/250/300?image=783',
title: 'Yes yes',
subtitle:
"<span class='font-weight-bold'>Bella</span> — Do you have Paris recommendations",
},
{
header: 'Yesterday',
},
{ divider: true },
{
avatar: 'https://picsum.photos/250/300?image=1006',
title: 'Dinner tonight?',
subtitle:
"<span class='font-weight-bold'>LaToya</span> — Do you want to hang out?",
},
{
avatar: 'https://picsum.photos/250/300?image=146',
title: 'So long',
subtitle:
"<span class='font-weight-bold'>Nancy</span> — Do you see what time it is?",
},
{
header: 'Last Week',
},
{ divider: true },
{
avatar: 'https://picsum.photos/250/300?image=1008',
title: 'Breakfast?',
subtitle:
"<span class='font-weight-bold'>LaToya</span> — Do you want to hang out?",
},
{
avatar: 'https://picsum.photos/250/300?image=839',
title:
'Winter Porridge <span class="grey--text text--lighten-1"></span>',
subtitle:
"<span class='font-weight-bold'>cc: Daniel</span> — Tell me more...",
},
{
avatar: 'https://picsum.photos/250/300?image=145',
title: 'Oui oui',
subtitle:
"<span class='font-weight-bold'>Nancy</span> — Do you see what time it is?",
},
],
}
},
}
</script>
人像视图中的分隔符
创建自定义卡片以适应任何用例
template
<template>
<v-row justify="center">
<v-col cols="12" sm="8">
<v-card>
<v-card-title class="cyan darken-1">
<span class="headline white--text">Sarah Mcbeal</span>
<v-spacer></v-spacer>
<v-btn dark icon>
<v-icon>mdi-chevron-left</v-icon>
</v-btn>
<v-btn dark icon>
<v-icon>mdi-pencil</v-icon>
</v-btn>
<v-btn dark icon>
<v-icon>mdi-dots-vertical</v-icon>
</v-btn>
</v-card-title>
<v-list>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-phone</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>(650) 555-1234</v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-icon>mdi-message-text</v-icon>
</v-list-item-action>
</v-list-item>
<v-divider inset></v-divider>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-phone</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>(323) 555-6789</v-list-item-title>
</v-list-item-content>
<v-list-item-action>
<v-icon>mdi-message-text</v-icon>
</v-list-item-action>
</v-list-item>
<v-divider inset></v-divider>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-email</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>mcbeal@example.com</v-list-item-title>
</v-list-item-content>
</v-list-item>
<v-divider inset></v-divider>
<v-list-item @click="">
<v-list-item-action>
<v-icon>mdi-map-marker</v-icon>
</v-list-item-action>
<v-list-item-content>
<v-list-item-title>Orlando, FL 79938</v-list-item-title>
</v-list-item-content>
</v-list-item>
</v-list>
<v-img
src="https://picsum.photos/700?image=996"
height="200px"
></v-img>
</v-card>
</v-col>
</v-row>
</template>
无障碍
默认情况下,v-diver
组件被分配给 WAI-ARIA 的角色 separator,它表示分隔符“分离并区分菜单项的内容部分或组别。 然而,有时分隔符只是使界面看起来很好的一种方式。在这种情况下, presentation 应使用表示“一个其隐性本地角色语义不会映射到可访问性 API 的元素”。 要覆盖默认的 separator 角色在 v-divider
中,只需添加一个 role="presentation"
属性到您的组件。 此外,v-divider
组件有一个 aria-orientation="vertical"
。如果 vertical="true"
,那么 aria-orientation="undefined"
也会自动设置。如果 role="presentation"
, aria-orientation="undefined"
,那么就会应用默认值。