分割线

v-divider 组件用于分隔列表或布局的各个部分。

用例

最简单的分隔线显示一条水平线。

template


  1. <template>
  2. <v-divider></v-divider>
  3. </template>

Dividers(分隔线) - 图1

API

从下面选择您想要的组件,并查看可用的属性、插槽、事件和函数。

Dividers(分隔线) - 图2

实战场

template script


  1. <template>
  2. <div class="grey lighten-5 pa-4">
  3. <v-toolbar
  4. v-if="variant === 'vertical'"
  5. color="gray"
  6. >
  7. <v-toolbar-title>Title</v-toolbar-title>
  8. <v-divider
  9. class="mx-4"
  10. :inset="inset"
  11. vertical
  12. ></v-divider>
  13. <v-spacer></v-spacer>
  14. <v-toolbar-items>
  15. <v-btn text>
  16. News
  17. </v-btn>
  18. <v-divider :inset="inset" vertical></v-divider>
  19. <v-btn text>
  20. Blog
  21. </v-btn>
  22. <v-divider :inset="inset" vertical></v-divider>
  23. <v-btn text>
  24. Music
  25. </v-btn>
  26. <v-divider :inset="inset" vertical></v-divider>
  27. </v-toolbar-items>
  28. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  29. </v-toolbar>
  30. <v-row v-else>
  31. <v-col cols="12" sm="6" offset-sm="3">
  32. <v-card>
  33. <v-list>
  34. <v-list-item @click="">
  35. <v-list-item-action>
  36. <v-icon>mdi-inbox-arrow-down</v-icon>
  37. </v-list-item-action>
  38. <v-list-item-content>
  39. <v-list-item-title>I'm a list item</v-list-item-title>
  40. </v-list-item-content>
  41. </v-list-item>
  42. <v-list-item @click="">
  43. <v-list-item-action>
  44. <v-icon>mdi-inbox-arrow-down</v-icon>
  45. </v-list-item-action>
  46. <v-list-item-content>
  47. <v-list-item-title>I'm a list item</v-list-item-title>
  48. </v-list-item-content>
  49. </v-list-item>
  50. <v-list-item @click="">
  51. <v-list-item-action>
  52. <v-icon>mdi-inbox-arrow-down</v-icon>
  53. </v-list-item-action>
  54. <v-list-item-content>
  55. <v-list-item-title>I'm a list item</v-list-item-title>
  56. </v-list-item-content>
  57. </v-list-item>
  58. <v-divider :inset="inset"></v-divider>
  59. <v-subheader>Subheader</v-subheader>
  60. <v-list-item @click="">
  61. <v-list-item-action>
  62. <v-icon>mdi-folder</v-icon>
  63. </v-list-item-action>
  64. <v-list-item-content>
  65. <v-list-item-title>I'm a list item</v-list-item-title>
  66. </v-list-item-content>
  67. </v-list-item>
  68. <v-divider :inset="inset"></v-divider>
  69. <v-list-item @click="">
  70. <v-list-item-action>
  71. <v-icon>mdi-folder</v-icon>
  72. </v-list-item-action>
  73. <v-list-item-content>
  74. <v-list-item-title>I'm a list item</v-list-item-title>
  75. </v-list-item-content>
  76. </v-list-item>
  77. <v-divider :inset="inset"></v-divider>
  78. <v-list-item @click="">
  79. <v-list-item-action>
  80. <v-icon>mdi-folder</v-icon>
  81. </v-list-item-action>
  82. <v-list-item-content>
  83. <v-list-item-title>I'm a list item</v-list-item-title>
  84. </v-list-item-content>
  85. </v-list-item>
  86. </v-list>
  87. </v-card>
  88. </v-col>
  89. </v-row>
  90. <v-row
  91. class="mt-12"
  92. align="center"
  93. justify="center"
  94. >
  95. <v-col
  96. cols="12"
  97. md="8"
  98. >
  99. <v-select
  100. v-model="variant"
  101. :items="items"
  102. clearable
  103. label="Variant"
  104. light
  105. ></v-select>
  106. <template>
  107. <v-checkbox
  108. v-model="inset"
  109. hide-details
  110. label="Inset"
  111. light
  112. ></v-checkbox>
  113. </template>
  114. </v-col>
  115. </v-row>
  116. </div>
  117. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. inset: false,
  5. items: [
  6. 'default',
  7. 'vertical',
  8. ],
  9. variant: 'default',
  10. }),
  11. }
  12. </script>

Dividers(分隔线) - 图3

示例

下面是一些简单到复杂的例子。

嵌入式分隔线

嵌入式分隔线向右移动 72px。 这将使他们与列表项对齐。

template script


  1. <template>
  2. <v-row>
  3. <v-col cols="12" sm="6" offset-sm="3">
  4. <v-card>
  5. <v-list two-line>
  6. <template v-for="(item, index) in items.slice(0, 6)">
  7. <v-subheader v-if="item.header" :key="item.header">{{ item.header }}</v-subheader>
  8. <v-divider v-else-if="item.divider" :key="index" :inset="item.inset"></v-divider>
  9. <v-list-item v-else :key="item.title" @click="">
  10. <v-list-item-avatar>
  11. <img :src="item.avatar">
  12. </v-list-item-avatar>
  13. <v-list-item-content>
  14. <v-list-item-title v-html="item.title"></v-list-item-title>
  15. <v-list-item-subtitle v-html="item.subtitle"></v-list-item-subtitle>
  16. </v-list-item-content>
  17. </v-list-item>
  18. </template>
  19. </v-list>
  20. </v-card>
  21. </v-col>
  22. </v-row>
  23. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. items: [
  5. { header: 'Today' },
  6. { avatar: 'https://cdn.vuetifyjs.com/images/lists/1.jpg', title: 'Brunch this weekend?', subtitle: "<span class='font-weight-bold'>Ali Connors</span> &mdash; I'll be in your neighborhood doing errands this weekend. Do you want to hang out?" },
  7. { divider: true, inset: true },
  8. { 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> &mdash; Wish I could come, but I'm out of town this weekend." },
  9. { divider: true, inset: true },
  10. { avatar: 'https://cdn.vuetifyjs.com/images/lists/3.jpg', title: 'Oui oui', subtitle: "<span class='font-weight-bold'>Sandra Adams</span> &mdash; Do you have Paris recommendations? Have you ever been?" },
  11. ],
  12. }),
  13. }
  14. </script>

Dividers(分隔线) - 图4

垂直分割线

垂直分隔线为您提供了更多用于独特布局的工具。

template


  1. <template>
  2. <v-toolbar
  3. color="purple"
  4. dark
  5. >
  6. <v-toolbar-title>Title</v-toolbar-title>
  7. <v-divider
  8. class="mx-4"
  9. vertical
  10. ></v-divider>
  11. <span class="subheading">My Home</span>
  12. <v-spacer></v-spacer>
  13. <v-toolbar-items class="hidden-sm-and-down">
  14. <v-btn text>
  15. News
  16. </v-btn>
  17. <v-divider vertical></v-divider>
  18. <v-btn text>
  19. Blog
  20. </v-btn>
  21. <v-divider vertical></v-divider>
  22. <v-btn text>
  23. Music
  24. </v-btn>
  25. <v-divider vertical></v-divider>
  26. </v-toolbar-items>
  27. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  28. </v-toolbar>
  29. </template>

Dividers(分隔线) - 图5

垂直的嵌入式分割线

垂直分割线还可以与 inset 属性一起使用,以获得更多选项。

template


  1. <template>
  2. <v-toolbar
  3. color="teal"
  4. dark
  5. >
  6. <v-toolbar-title>Title</v-toolbar-title>
  7. <v-divider
  8. class="mx-4"
  9. inset
  10. vertical
  11. ></v-divider>
  12. <span class="subheading">My Home</span>
  13. <v-spacer></v-spacer>
  14. <v-toolbar-items class="hidden-sm-and-down">
  15. <v-btn text>
  16. News
  17. </v-btn>
  18. <v-divider
  19. inset
  20. vertical
  21. ></v-divider>
  22. <v-btn text>
  23. Blog
  24. </v-btn>
  25. <v-divider
  26. inset
  27. vertical
  28. ></v-divider>
  29. <v-btn text>
  30. Music
  31. </v-btn>
  32. <v-divider
  33. inset
  34. vertical
  35. ></v-divider>
  36. </v-toolbar-items>
  37. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  38. </v-toolbar>
  39. </template>

Dividers(分隔线) - 图6

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


  1. <template>
  2. <v-row justify="center">
  3. <v-col cols="12" sm="8" md="6">
  4. <v-card>
  5. <v-toolbar color="orange lighten-1" dark>
  6. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  7. <v-toolbar-title>Message Board</v-toolbar-title>
  8. <v-spacer></v-spacer>
  9. <v-btn icon>
  10. <v-icon>mdi-magnify</v-icon>
  11. </v-btn>
  12. </v-toolbar>
  13. <v-list two-line>
  14. <template v-for="(item, index) in items">
  15. <v-subheader
  16. v-if="item.header"
  17. :key="item.header"
  18. inset
  19. >
  20. {{ item.header }}
  21. </v-subheader>
  22. <v-divider
  23. v-else-if="item.divider"
  24. :key="index"
  25. inset
  26. ></v-divider>
  27. <v-list-item
  28. v-else
  29. :key="item.title"
  30. ripple
  31. @click=""
  32. >
  33. <v-list-item-avatar>
  34. <img :src="item.avatar">
  35. </v-list-item-avatar>
  36. <v-list-item-content>
  37. <v-list-item-title v-html="item.title"></v-list-item-title>
  38. <v-list-item-subtitle v-html="item.subtitle"></v-list-item-subtitle>
  39. </v-list-item-content>
  40. </v-list-item>
  41. </template>
  42. </v-list>
  43. </v-card>
  44. </v-col>
  45. </v-row>
  46. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. items: [
  6. {
  7. header: 'Today',
  8. },
  9. { divider: true },
  10. {
  11. avatar: 'https://picsum.photos/250/300?image=660',
  12. title: 'Meeting @ Noon',
  13. subtitle:
  14. "<span class='font-weight-bold'>Spike Lee</span> &mdash; I'll be in your neighborhood",
  15. },
  16. {
  17. avatar: 'https://picsum.photos/250/300?image=821',
  18. title: 'Summer BBQ <span class="grey--text text--lighten-1"></span>',
  19. subtitle:
  20. "<span class='font-weight-bold'>to Operations support</span> &mdash; Wish I could come.",
  21. },
  22. {
  23. avatar: 'https://picsum.photos/250/300?image=783',
  24. title: 'Yes yes',
  25. subtitle:
  26. "<span class='font-weight-bold'>Bella</span> &mdash; Do you have Paris recommendations",
  27. },
  28. {
  29. header: 'Yesterday',
  30. },
  31. { divider: true },
  32. {
  33. avatar: 'https://picsum.photos/250/300?image=1006',
  34. title: 'Dinner tonight?',
  35. subtitle:
  36. "<span class='font-weight-bold'>LaToya</span> &mdash; Do you want to hang out?",
  37. },
  38. {
  39. avatar: 'https://picsum.photos/250/300?image=146',
  40. title: 'So long',
  41. subtitle:
  42. "<span class='font-weight-bold'>Nancy</span> &mdash; Do you see what time it is?",
  43. },
  44. {
  45. header: 'Last Week',
  46. },
  47. { divider: true },
  48. {
  49. avatar: 'https://picsum.photos/250/300?image=1008',
  50. title: 'Breakfast?',
  51. subtitle:
  52. "<span class='font-weight-bold'>LaToya</span> &mdash; Do you want to hang out?",
  53. },
  54. {
  55. avatar: 'https://picsum.photos/250/300?image=839',
  56. title:
  57. 'Winter Porridge <span class="grey--text text--lighten-1"></span>',
  58. subtitle:
  59. "<span class='font-weight-bold'>cc: Daniel</span> &mdash; Tell me more...",
  60. },
  61. {
  62. avatar: 'https://picsum.photos/250/300?image=145',
  63. title: 'Oui oui',
  64. subtitle:
  65. "<span class='font-weight-bold'>Nancy</span> &mdash; Do you see what time it is?",
  66. },
  67. ],
  68. }
  69. },
  70. }
  71. </script>

Dividers(分隔线) - 图7

人像视图中的分隔符

创建自定义卡片以适应任何用例

template


  1. <template>
  2. <v-row justify="center">
  3. <v-col cols="12" sm="8">
  4. <v-card>
  5. <v-card-title class="cyan darken-1">
  6. <span class="headline white--text">Sarah Mcbeal</span>
  7. <v-spacer></v-spacer>
  8. <v-btn dark icon>
  9. <v-icon>mdi-chevron-left</v-icon>
  10. </v-btn>
  11. <v-btn dark icon>
  12. <v-icon>mdi-pencil</v-icon>
  13. </v-btn>
  14. <v-btn dark icon>
  15. <v-icon>mdi-dots-vertical</v-icon>
  16. </v-btn>
  17. </v-card-title>
  18. <v-list>
  19. <v-list-item @click="">
  20. <v-list-item-action>
  21. <v-icon>mdi-phone</v-icon>
  22. </v-list-item-action>
  23. <v-list-item-content>
  24. <v-list-item-title>(650) 555-1234</v-list-item-title>
  25. </v-list-item-content>
  26. <v-list-item-action>
  27. <v-icon>mdi-message-text</v-icon>
  28. </v-list-item-action>
  29. </v-list-item>
  30. <v-divider inset></v-divider>
  31. <v-list-item @click="">
  32. <v-list-item-action>
  33. <v-icon>mdi-phone</v-icon>
  34. </v-list-item-action>
  35. <v-list-item-content>
  36. <v-list-item-title>(323) 555-6789</v-list-item-title>
  37. </v-list-item-content>
  38. <v-list-item-action>
  39. <v-icon>mdi-message-text</v-icon>
  40. </v-list-item-action>
  41. </v-list-item>
  42. <v-divider inset></v-divider>
  43. <v-list-item @click="">
  44. <v-list-item-action>
  45. <v-icon>mdi-email</v-icon>
  46. </v-list-item-action>
  47. <v-list-item-content>
  48. <v-list-item-title>mcbeal@example.com</v-list-item-title>
  49. </v-list-item-content>
  50. </v-list-item>
  51. <v-divider inset></v-divider>
  52. <v-list-item @click="">
  53. <v-list-item-action>
  54. <v-icon>mdi-map-marker</v-icon>
  55. </v-list-item-action>
  56. <v-list-item-content>
  57. <v-list-item-title>Orlando, FL 79938</v-list-item-title>
  58. </v-list-item-content>
  59. </v-list-item>
  60. </v-list>
  61. <v-img
  62. src="https://picsum.photos/700?image=996"
  63. height="200px"
  64. ></v-img>
  65. </v-card>
  66. </v-col>
  67. </v-row>
  68. </template>

Dividers(分隔线) - 图8

无障碍

默认情况下,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",那么就会应用默认值。