选项卡

v-tabs 组件用于将内容隐藏在可选项之后。这还可以用作页面的伪导航,其中选项卡是链接,选项卡项是内容。

用例

v-tabs 组件是 v-item-group 的样式扩展。它提供了一个易于使用的接口来组织内容组。

template


  1. <template>
  2. <v-tabs>
  3. <v-tab>Item One</v-tab>
  4. <v-tab>Item Two</v-tab>
  5. <v-tab>Item Three</v-tab>
  6. </v-tabs>
  7. </template>

Tabs(选项卡) - 图1

当使用 dark 属性和 提供自定义 color 时,v-tabs 组件会将其颜色默认为 _white_。

当使用包含必填输入字段的 v-tab-item 时,你必须使用 eager prop 来验证尚未显示的必填字段。

API

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

Tabs(选项卡) - 图2

实战场

template script


  1. <template>
  2. <div>
  3. <v-row
  4. justify="space-around"
  5. >
  6. <v-switch
  7. v-model="icons"
  8. class="mx-2"
  9. label="Text + icons"
  10. ></v-switch>
  11. <v-switch
  12. v-model="centered"
  13. class="mx-2"
  14. label="Centered"
  15. :disabled="vertical"
  16. ></v-switch>
  17. <v-switch
  18. v-model="grow"
  19. class="mx-2"
  20. label="Grow"
  21. ></v-switch>
  22. <v-switch
  23. v-model="vertical"
  24. class="mx-2"
  25. label="Vertical"
  26. ></v-switch>
  27. <v-switch
  28. v-model="right"
  29. class="mx-2"
  30. label="Right"
  31. ></v-switch>
  32. <v-col cols="12">
  33. <v-slider
  34. v-model="tabs"
  35. min="0"
  36. max="10"
  37. label="Tabs number"
  38. ></v-slider>
  39. </v-col>
  40. </v-row>
  41. <v-tabs
  42. v-model="tab"
  43. background-color="deep-purple accent-4"
  44. class="elevation-2"
  45. dark
  46. :centered="centered"
  47. :grow="grow"
  48. :vertical="vertical"
  49. :right="right"
  50. :prev-icon="prevIcon ? 'mdi-arrow-left-bold-box-outline' : undefined"
  51. :next-icon="nextIcon ? 'mdi-arrow-right-bold-box-outline' : undefined"
  52. :icons-and-text="icons"
  53. >
  54. <v-tabs-slider></v-tabs-slider>
  55. <v-tab
  56. v-for="i in tabs"
  57. :key="i"
  58. :href="`#tab-${i}`"
  59. >
  60. Tab {{ i }}
  61. <v-icon v-if="icons">mdi-phone</v-icon>
  62. </v-tab>
  63. <v-tab-item
  64. v-for="i in tabs"
  65. :key="i"
  66. :value="'tab-' + i"
  67. >
  68. <v-card
  69. flat
  70. tile
  71. >
  72. <v-card-text>{{ text }}</v-card-text>
  73. </v-card>
  74. </v-tab-item>
  75. </v-tabs>
  76. </div>
  77. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tab: null,
  6. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  7. icons: false,
  8. centered: false,
  9. grow: false,
  10. vertical: false,
  11. prevIcon: false,
  12. nextIcon: false,
  13. right: false,
  14. tabs: 3,
  15. }
  16. },
  17. }
  18. </script>

Tabs(选项卡) - 图3

示例

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

固定选项卡

fixed-tabs 属性强制 v-tab 占用所有可用空间,直到最大宽度(300px)。

template


  1. <template>
  2. <v-tabs
  3. fixed-tabs
  4. background-color="indigo"
  5. dark
  6. >
  7. <v-tab>
  8. Option
  9. </v-tab>
  10. <v-tab>
  11. Another Selection
  12. </v-tab>
  13. <v-tab>
  14. Items
  15. </v-tab>
  16. <v-tab>
  17. Another Screen
  18. </v-tab>
  19. </v-tabs>
  20. </template>

Tabs(选项卡) - 图4

居中活动选项卡

活动选项卡总是居中

template


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. background-color="deep-purple accent-4"
  5. center-active
  6. dark
  7. >
  8. <v-tab>One</v-tab>
  9. <v-tab>Two</v-tab>
  10. <v-tab>Three</v-tab>
  11. <v-tab>Four</v-tab>
  12. <v-tab>Five</v-tab>
  13. <v-tab>Six</v-tab>
  14. <v-tab>Seven</v-tab>
  15. <v-tab>Eight</v-tab>
  16. <v-tab>Nine</v-tab>
  17. <v-tab>Ten</v-tab>
  18. <v-tab>Eleven</v-tab>
  19. <v-tab>Twelve</v-tab>
  20. <v-tab>Thirteen</v-tab>
  21. <v-tab>Fourteen</v-tab>
  22. <v-tab>Fifteen</v-tab>
  23. <v-tab>Sixteen</v-tab>
  24. <v-tab>Seventeen</v-tab>
  25. <v-tab>Eighteen</v-tab>
  26. <v-tab>Nineteen</v-tab>
  27. <v-tab>Twenty</v-tab>
  28. </v-tabs>
  29. </v-card>
  30. </template>

Tabs(选项卡) - 图5

选项卡项目

v-tabs-items 组件允许你自定义每个标签的内容。使用共享的 v-modelv-tabs-items 将与当前选择的 v-tab 同步。

template script


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. v-model="tab"
  5. background-color="primary"
  6. dark
  7. >
  8. <v-tab
  9. v-for="item in items"
  10. :key="item.tab"
  11. >
  12. {{ item.tab }}
  13. </v-tab>
  14. </v-tabs>
  15. <v-tabs-items v-model="tab">
  16. <v-tab-item
  17. v-for="item in items"
  18. :key="item.tab"
  19. >
  20. <v-card flat>
  21. <v-card-text>{{ item.content }}</v-card-text>
  22. </v-card>
  23. </v-tab-item>
  24. </v-tabs-items>
  25. </v-card>
  26. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tab: null,
  6. items: [
  7. { tab: 'One', content: 'Tab 1 Content' },
  8. { tab: 'Two', content: 'Tab 2 Content' },
  9. { tab: 'Three', content: 'Tab 3 Content' },
  10. { tab: 'Four', content: 'Tab 4 Content' },
  11. { tab: 'Five', content: 'Tab 5 Content' },
  12. { tab: 'Six', content: 'Tab 6 Content' },
  13. { tab: 'Seven', content: 'Tab 7 Content' },
  14. { tab: 'Eight', content: 'Tab 8 Content' },
  15. { tab: 'Nine', content: 'Tab 9 Content' },
  16. { tab: 'Ten', content: 'Tab 10 Content' },
  17. ],
  18. }
  19. },
  20. }
  21. </script>

Tabs(选项卡) - 图6

扩大

grow 属性将使选项卡项目占用所有可用空间,最大宽度为 300px。

template script style


  1. <template>
  2. <v-card color="basil">
  3. <v-card-title class="text-center justify-center py-6">
  4. <h1 class="font-weight-bold display-3 basil--text">BASiL</h1>
  5. </v-card-title>
  6. <v-tabs
  7. v-model="tab"
  8. background-color="transparent"
  9. color="basil"
  10. grow
  11. >
  12. <v-tab
  13. v-for="item in items"
  14. :key="item"
  15. >
  16. {{ item }}
  17. </v-tab>
  18. </v-tabs>
  19. <v-tabs-items v-model="tab">
  20. <v-tab-item
  21. v-for="item in items"
  22. :key="item"
  23. >
  24. <v-card
  25. color="basil"
  26. flat
  27. >
  28. <v-card-text>{{ text }}</v-card-text>
  29. </v-card>
  30. </v-tab-item>
  31. </v-tabs-items>
  32. </v-card>
  33. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tab: null,
  6. items: [
  7. 'Appetizers', 'Entrees', 'Deserts', 'Cocktails',
  8. ],
  9. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  10. }
  11. },
  12. }
  13. </script>
  1. <style>
  2. /* Helper classes */
  3. .basil {
  4. background-color: #FFFBE6 !important;
  5. }
  6. .basil--text {
  7. color: #356859 !important;
  8. }
  9. </style>

Tabs(选项卡) - 图7

分页

如果选项卡项目超出其容器,则分页控件将出现在桌面设备。 对于移动设备,箭头将仅与 show-arrows 属性一起显示。

template


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. dark
  5. background-color="teal darken-3"
  6. show-arrows
  7. >
  8. <v-tabs-slider color="teal lighten-3"></v-tabs-slider>
  9. <v-tab
  10. v-for="i in 30"
  11. :key="i"
  12. :href="'#tab-' + i"
  13. >
  14. Item {{ i }}
  15. </v-tab>
  16. </v-tabs>
  17. </v-card>
  18. </template>

Tabs(选项卡) - 图8

自定义图标

prev-icon 和* next-icon* 可以用来设置分页器的自定义图标

template


  1. <template>
  2. <v-sheet elevation="6">
  3. <v-tabs
  4. background-color="cyan"
  5. dark
  6. next-icon="mdi-arrow-right-bold-box-outline"
  7. prev-icon="mdi-arrow-left-bold-box-outline"
  8. show-arrows
  9. >
  10. <v-tabs-slider color="yellow"></v-tabs-slider>
  11. <v-tab
  12. v-for="i in 30"
  13. :key="i"
  14. :href="'#tab-' + i"
  15. >
  16. Item {{ i }}
  17. </v-tab>
  18. </v-tabs>
  19. </v-sheet>
  20. </template>

Tabs(选项卡) - 图9

垂直选项卡

标签可以切换为垂直堆叠其 v-tab 组件。

template


  1. <template>
  2. <v-card>
  3. <v-toolbar flat color="primary" dark>
  4. <v-toolbar-title>User Profile</v-toolbar-title>
  5. </v-toolbar>
  6. <v-tabs vertical>
  7. <v-tab>
  8. <v-icon left>mdi-account</v-icon>
  9. Option 1
  10. </v-tab>
  11. <v-tab>
  12. <v-icon left>mdi-lock</v-icon>
  13. Option 2
  14. </v-tab>
  15. <v-tab>
  16. <v-icon left>mdi-access-point</v-icon>
  17. Option 3
  18. </v-tab>
  19. <v-tab-item>
  20. <v-card flat>
  21. <v-card-text>
  22. <p>
  23. Sed aliquam ultrices mauris. Donec posuere vulputate arcu. Morbi ac felis. Etiam feugiat lorem non metus. Sed a libero.
  24. </p>
  25. <p>
  26. Nam ipsum risus, rutrum vitae, vestibulum eu, molestie vel, lacus. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc. Aliquam lobortis. Aliquam lobortis. Suspendisse non nisl sit amet velit hendrerit rutrum.
  27. </p>
  28. <p class="mb-0">
  29. Phasellus dolor. Fusce neque. Fusce fermentum odio nec arcu. Pellentesque libero tortor, tincidunt et, tincidunt eget, semper nec, quam. Phasellus blandit leo ut odio.
  30. </p>
  31. </v-card-text>
  32. </v-card>
  33. </v-tab-item>
  34. <v-tab-item>
  35. <v-card flat>
  36. <v-card-text>
  37. <p>
  38. Morbi nec metus. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Sed mollis, eros et ultrices tempus, mauris ipsum aliquam libero, non adipiscing dolor urna a orci. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Nunc sed turpis.
  39. </p>
  40. <p>
  41. Suspendisse feugiat. Suspendisse faucibus, nunc et pellentesque egestas, lacus ante convallis tellus, vitae iaculis lacus elit id tortor. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. In hac habitasse platea dictumst. Fusce ac felis sit amet ligula pharetra condimentum.
  42. </p>
  43. <p>
  44. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Nam commodo suscipit quam. In consectetuer turpis ut velit. Sed cursus turpis vitae tortor. Aliquam eu nunc.
  45. </p>
  46. <p>
  47. Etiam ut purus mattis mauris sodales aliquam. Ut varius tincidunt libero. Aenean viverra rhoncus pede. Duis leo. Fusce fermentum odio nec arcu.
  48. </p>
  49. <p class="mb-0">
  50. Donec venenatis vulputate lorem. Aenean viverra rhoncus pede. In dui magna, posuere eget, vestibulum et, tempor auctor, justo. Fusce commodo aliquam arcu. Suspendisse enim turpis, dictum sed, iaculis a, condimentum nec, nisi.
  51. </p>
  52. </v-card-text>
  53. </v-card>
  54. </v-tab-item>
  55. <v-tab-item>
  56. <v-card flat>
  57. <v-card-text>
  58. <p>
  59. Fusce a quam. Phasellus nec sem in justo pellentesque facilisis. Nam eget dui. Proin viverra, ligula sit amet ultrices semper, ligula arcu tristique sapien, a accumsan nisi mauris ac eros. In dui magna, posuere eget, vestibulum et, tempor auctor, justo.
  60. </p>
  61. <p class="mb-0">
  62. Cras sagittis. Phasellus nec sem in justo pellentesque facilisis. Proin sapien ipsum, porta a, auctor quis, euismod ut, mi. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nam at tortor in tellus interdum sagittis.
  63. </p>
  64. </v-card-text>
  65. </v-card>
  66. </v-tab-item>
  67. </v-tabs>
  68. </v-card>
  69. </template>

Tabs(选项卡) - 图10

图标和文本

v-tab 可以包含图标和文本。这将 v-tabs 的高度增加到 72px。

template script


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. v-model="tab"
  5. background-color="deep-purple accent-4"
  6. centered
  7. dark
  8. icons-and-text
  9. >
  10. <v-tabs-slider></v-tabs-slider>
  11. <v-tab href="#tab-1">
  12. Recents
  13. <v-icon>mdi-phone</v-icon>
  14. </v-tab>
  15. <v-tab href="#tab-2">
  16. Favorites
  17. <v-icon>mdi-heart</v-icon>
  18. </v-tab>
  19. <v-tab href="#tab-3">
  20. Nearby
  21. <v-icon>mdi-account-box</v-icon>
  22. </v-tab>
  23. </v-tabs>
  24. <v-tabs-items v-model="tab">
  25. <v-tab-item
  26. v-for="i in 3"
  27. :key="i"
  28. :value="'tab-' + i"
  29. >
  30. <v-card flat>
  31. <v-card-text>{{ text }}</v-card-text>
  32. </v-card>
  33. </v-tab-item>
  34. </v-tabs-items>
  35. </v-card>
  36. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tab: null,
  6. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  7. }
  8. },
  9. }
  10. </script>

Tabs(选项卡) - 图11

Charcoal Vuetify Beanie

Stay warm with the new Premium Knit Vuetify Beanie available in black, navy and charcoal.

ads by Vuetify

](https://store.vuetifyjs.com/product/premium-charcoal-vuetify-beanie?ref=vuetifyjs.com)

右对齐选项卡

right属性将选项卡向右对齐。

template


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. background-color="white"
  5. color="deep-purple accent-4"
  6. right
  7. >
  8. <v-tab>Landscape</v-tab>
  9. <v-tab>City</v-tab>
  10. <v-tab>Abstract</v-tab>
  11. <v-tab-item
  12. v-for="n in 3"
  13. :key="n"
  14. >
  15. <v-container fluid>
  16. <v-row>
  17. <v-col
  18. v-for="i in 6"
  19. :key="i"
  20. cols="12"
  21. md="4"
  22. >
  23. <v-img
  24. :src="`https://picsum.photos/500/300?image=${i * n * 5 + 10}`"
  25. :lazy-src="`https://picsum.photos/10/6?image=${i * n * 5 + 10}`"
  26. aspect-ratio="1"
  27. ></v-img>
  28. </v-col>
  29. </v-row>
  30. </v-container>
  31. </v-tab-item>
  32. </v-tabs>
  33. </v-card>
  34. </template>

Tabs(选项卡) - 图12

内容

通常把 v-tabs 放在 v-toolbarextension 插槽内。使用 v-toolbartabs 属性自动调整其高度为 48px,以匹配 v-tabs

template script


  1. <template>
  2. <v-card>
  3. <v-toolbar
  4. color="cyan"
  5. dark
  6. flat
  7. >
  8. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  9. <v-toolbar-title>Page title</v-toolbar-title>
  10. <v-spacer></v-spacer>
  11. <v-btn icon>
  12. <v-icon>mdi-magnify</v-icon>
  13. </v-btn>
  14. <v-btn icon>
  15. <v-icon>mdi-dots-vertical</v-icon>
  16. </v-btn>
  17. <template v-slot:extension>
  18. <v-tabs
  19. v-model="model"
  20. centered
  21. slider-color="yellow"
  22. >
  23. <v-tab
  24. v-for="i in 3"
  25. :key="i"
  26. :href="`#tab-${i}`"
  27. >
  28. Item {{ i }}
  29. </v-tab>
  30. </v-tabs>
  31. </template>
  32. </v-toolbar>
  33. <v-tabs-items v-model="model">
  34. <v-tab-item
  35. v-for="i in 3"
  36. :key="i"
  37. :value="`tab-${i}`"
  38. >
  39. <v-card flat>
  40. <v-card-text v-text="text"></v-card-text>
  41. </v-card>
  42. </v-tab-item>
  43. </v-tabs-items>
  44. </v-card>
  45. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. model: 'tab-2',
  6. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  7. }
  8. },
  9. }
  10. </script>

Tabs(选项卡) - 图13

与工具栏标题对齐选项卡

v-tabsv-toolbar-title 组件对齐(v-toolbar 中必须使用 v-app-bar-nav-iconv-btn )。

template script


  1. <template>
  2. <v-card>
  3. <v-toolbar
  4. color="cyan"
  5. dark
  6. flat
  7. >
  8. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  9. <v-toolbar-title>Your Dashboard</v-toolbar-title>
  10. <v-spacer></v-spacer>
  11. <v-btn icon>
  12. <v-icon>mdi-magnify</v-icon>
  13. </v-btn>
  14. <v-btn icon>
  15. <v-icon>mdi-dots-vertical</v-icon>
  16. </v-btn>
  17. <template v-slot:extension>
  18. <v-tabs
  19. v-model="tab"
  20. align-with-title
  21. >
  22. <v-tabs-slider color="yellow"></v-tabs-slider>
  23. <v-tab v-for="item in items" :key="item">
  24. {{ item }}
  25. </v-tab>
  26. </v-tabs>
  27. </template>
  28. </v-toolbar>
  29. <v-tabs-items v-model="tab">
  30. <v-tab-item
  31. v-for="item in items"
  32. :key="item"
  33. >
  34. <v-card flat>
  35. <v-card-text v-text="text"></v-card-text>
  36. </v-card>
  37. </v-tab-item>
  38. </v-tabs-items>
  39. </v-card>
  40. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tab: null,
  6. items: [
  7. 'web', 'shopping', 'videos', 'images', 'news',
  8. ],
  9. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  10. }
  11. },
  12. }
  13. </script>

Tabs(选项卡) - 图14

动态选项卡

选项卡可以动态添加和删除。 这使您可以更新为任意数量,并且 v-tabs 组件会做出反应。 在此示例中,当我们添加新标签时,我们会自动更改模型以使其匹配。 随着我们添加更多标签并溢出容器,所选项目将自动滚动到视图中。 删除所有的 v-tabs,滑块将消失。

template script


  1. <template>
  2. <v-card>
  3. <v-tabs
  4. v-model="tab"
  5. background-color="red lighten-2"
  6. dark
  7. >
  8. <v-tab
  9. v-for="n in length"
  10. :key="n"
  11. >
  12. Item {{ n }}
  13. </v-tab>
  14. </v-tabs>
  15. <v-card-text class="text-center">
  16. <v-btn text @click="length--">Remove Tab</v-btn>
  17. <v-divider class="mx-4" vertical></v-divider>
  18. <v-btn text @click="length++">Add Tab</v-btn>
  19. </v-card-text>
  20. </v-card>
  21. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. length: 15,
  5. tab: null,
  6. }),
  7. watch: {
  8. length (val) {
  9. this.tab = val - 1
  10. },
  11. },
  12. }
  13. </script>

Tabs(选项卡) - 图15

搜索框

更改 v-tab-item 时,内容区域将平滑缩放到新的大小。

template script


  1. <template>
  2. <v-card>
  3. <v-toolbar
  4. color="purple"
  5. dark
  6. flat
  7. prominent
  8. >
  9. <v-text-field
  10. append-icon="mic"
  11. class="mx-4"
  12. flat
  13. hide-details
  14. label="Search"
  15. prepend-inner-icon="search"
  16. solo-inverted
  17. ></v-text-field>
  18. <template v-slot:extension>
  19. <v-tabs
  20. v-model="tabs"
  21. centered
  22. >
  23. <v-tab
  24. v-for="n in 3"
  25. :key="n"
  26. >
  27. Item {{ n }}
  28. </v-tab>
  29. </v-tabs>
  30. </template>
  31. </v-toolbar>
  32. <v-tabs-items v-model="tabs">
  33. <v-tab-item>
  34. <v-card flat>
  35. <v-card-text>
  36. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  37. </v-card-text>
  38. </v-card>
  39. </v-tab-item>
  40. <v-tab-item>
  41. <v-card flat>
  42. <v-card-title class="headline">An awesome title</v-card-title>
  43. <v-card-text>
  44. <p>
  45. Duis lobortis massa imperdiet quam. Donec vitae orci sed dolor rutrum auctor. Vestibulum facilisis, purus nec pulvinar iaculis, ligula mi congue nunc, vitae euismod ligula urna in dolor. Praesent congue erat at massa.
  46. </p>
  47. <p>
  48. Aenean posuere, tortor sed cursus feugiat, nunc augue blandit nunc, eu sollicitudin urna dolor sagittis lacus. Pellentesque egestas, neque sit amet convallis pulvinar, justo nulla eleifend augue, ac auctor orci leo non est. Etiam sit amet orci eget eros faucibus tincidunt. Donec sodales sagittis magna.
  49. </p>
  50. <p class="mb-0">
  51. Ut leo. Suspendisse potenti. Duis vel nibh at velit scelerisque suscipit. Fusce pharetra convallis urna.
  52. </p>
  53. </v-card-text>
  54. </v-card>
  55. </v-tab-item>
  56. <v-tab-item>
  57. <v-card flat>
  58. <v-card-title class="headline">An even better title</v-card-title>
  59. <v-card-text>
  60. <p>
  61. Maecenas ullamcorper, dui et placerat feugiat, eros pede varius nisi, condimentum viverra felis nunc et lorem. Sed hendrerit. Maecenas malesuada. Vestibulum ullamcorper mauris at ligula. Proin faucibus arcu quis ante.
  62. </p>
  63. <p class="mb-0">
  64. Etiam vitae tortor. Curabitur ullamcorper ultricies nisi. Sed magna purus, fermentum eu, tincidunt eu, varius ut, felis. Aliquam lobortis. Suspendisse potenti.
  65. </p>
  66. </v-card-text>
  67. </v-card>
  68. </v-tab-item>
  69. </v-tabs-items>
  70. </v-card>
  71. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tabs: null,
  6. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  7. }
  8. },
  9. }
  10. </script>

Tabs(选项卡) - 图16

桌面选项卡

你可以用单个图标来表示 v-tab 的操作。当很容易将内容与每个选项卡关联起来时,这是很有用的。

template script


  1. <template>
  2. <v-card>
  3. <v-toolbar flat>
  4. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  5. <v-toolbar-title>Contact Database</v-toolbar-title>
  6. <v-spacer></v-spacer>
  7. <v-btn icon>
  8. <v-icon>mdi-magnify</v-icon>
  9. </v-btn>
  10. <v-btn icon>
  11. <v-icon>mdi-dots-vertical</v-icon>
  12. </v-btn>
  13. <template v-slot:extension>
  14. <v-tabs
  15. v-model="tabs"
  16. fixed-tabs
  17. >
  18. <v-tabs-slider></v-tabs-slider>
  19. <v-tab
  20. href="#mobile-tabs-5-1"
  21. class="primary--text"
  22. >
  23. <v-icon>mdi-phone</v-icon>
  24. </v-tab>
  25. <v-tab
  26. href="#mobile-tabs-5-2"
  27. class="primary--text"
  28. >
  29. <v-icon>mdi-heart</v-icon>
  30. </v-tab>
  31. <v-tab
  32. href="#mobile-tabs-5-3"
  33. class="primary--text"
  34. >
  35. <v-icon>mdi-account-box</v-icon>
  36. </v-tab>
  37. </v-tabs>
  38. </template>
  39. </v-toolbar>
  40. <v-tabs-items v-model="tabs">
  41. <v-tab-item
  42. v-for="i in 3"
  43. :key="i"
  44. :value="'mobile-tabs-5-' + i"
  45. >
  46. <v-card flat>
  47. <v-card-text v-text="text"></v-card-text>
  48. </v-card>
  49. </v-tab-item>
  50. </v-tabs-items>
  51. </v-card>
  52. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. tabs: null,
  6. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  7. }
  8. },
  9. }
  10. </script>

Tabs(选项卡) - 图17

带菜单

您可以使用菜单来保存额外的选项卡,动态地将它们交换出来。

template script


  1. <template>
  2. <v-card>
  3. <v-toolbar
  4. color="deep-purple accent-4"
  5. dark
  6. flat
  7. >
  8. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  9. <v-toolbar-title>Page title</v-toolbar-title>
  10. <v-spacer></v-spacer>
  11. <v-btn icon>
  12. <v-icon>mdi-magnify</v-icon>
  13. </v-btn>
  14. <v-btn icon>
  15. <v-icon>mdi-dots-vertical</v-icon>
  16. </v-btn>
  17. <template v-slot:extension>
  18. <v-tabs
  19. v-model="currentItem"
  20. fixed-tabs
  21. slider-color="white"
  22. >
  23. <v-tab
  24. v-for="item in items"
  25. :key="item"
  26. :href="'#tab-' + item"
  27. >
  28. {{ item }}
  29. </v-tab>
  30. <v-menu
  31. v-if="more.length"
  32. bottom
  33. left
  34. >
  35. <template v-slot:activator="{ on }">
  36. <v-btn
  37. text
  38. class="align-self-center mr-4"
  39. v-on="on"
  40. >
  41. more
  42. <v-icon right>mdi-menu-down</v-icon>
  43. </v-btn>
  44. </template>
  45. <v-list class="grey lighten-3">
  46. <v-list-item
  47. v-for="item in more"
  48. :key="item"
  49. @click="addItem(item)"
  50. >
  51. {{ item }}
  52. </v-list-item>
  53. </v-list>
  54. </v-menu>
  55. </v-tabs>
  56. </template>
  57. </v-toolbar>
  58. <v-tabs-items v-model="currentItem">
  59. <v-tab-item
  60. v-for="item in items.concat(more)"
  61. :key="item"
  62. :value="'tab-' + item"
  63. >
  64. <v-card flat>
  65. <v-card-text>
  66. <h2>{{ item }}</h2>
  67. {{ text }}
  68. </v-card-text>
  69. </v-card>
  70. </v-tab-item>
  71. </v-tabs-items>
  72. </v-card>
  73. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. currentItem: 'tab-Web',
  5. items: [
  6. 'Web', 'Shopping', 'Videos', 'Images',
  7. ],
  8. more: [
  9. 'News', 'Maps', 'Books', 'Flights', 'Apps',
  10. ],
  11. text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.',
  12. }),
  13. methods: {
  14. addItem (item) {
  15. const removed = this.items.splice(0, 1)
  16. this.items.push(
  17. ...this.more.splice(this.more.indexOf(item), 1)
  18. )
  19. this.more.push(...removed)
  20. this.$nextTick(() => { this.currentItem = 'tab-' + item })
  21. },
  22. },
  23. }
  24. </script>

Tabs(选项卡) - 图18