卡片

v-card 组件是一种多功能组件,可用于从面板到静态图像的任何东西。 card 组件有许多助手组件,以使标记尽可能简单。没有列出选项的组件使用 Vue的 功能组件选项来加快渲染速度,并充当标记糖来简化构建。

用例

卡片有 4 个基本组件:v-card-title, v-card-subtitle, v-card-textv-card-actions

Cards(卡片) - 图1

函数组件

  • v-card-actions:用于放置卡片的 动作 的容器,例如 v-btnv-menu。也为按钮应用了 special margin 以使它们与其他卡的内容区域保持一致。
  • v-card-subtitle:为卡片字幕提供了一个默认的 字体大小间距,字体大小可以用 typography classes 覆盖。
  • v-card-text:主要用于卡片中的 文字内容。对文字进行填充,将其字体大小减少到 .875rem。
  • v-card-title:为卡片标题提供一个默认的 字体大小间距。字体大小可以用 typography classes 覆盖。

API

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

Cards(卡片) - 图2

示例

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

轮廓卡片

outlined 卡片的海拔为0,并且包含边框。

template


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="344"
  5. outlined
  6. >
  7. <v-list-item three-line>
  8. <v-list-item-content>
  9. <div class="overline mb-4">OVERLINE</div>
  10. <v-list-item-title class="headline mb-1">Headline 5</v-list-item-title>
  11. <v-list-item-subtitle>Greyhound divisely hello coldly fonwderfully</v-list-item-subtitle>
  12. </v-list-item-content>
  13. <v-list-item-avatar
  14. tile
  15. size="80"
  16. color="grey"
  17. ></v-list-item-avatar>
  18. </v-list-item>
  19. <v-card-actions>
  20. <v-btn text>Button</v-btn>
  21. <v-btn text>Button</v-btn>
  22. </v-card-actions>
  23. </v-card>
  24. </template>

Cards(卡片) - 图3

中间值

v-card 组件对于包装内容非常有用。

template


  1. <template>
  2. <v-card class="d-inline-block mx-auto">
  3. <v-container>
  4. <v-row justify="space-between">
  5. <v-col cols="auto">
  6. <v-img
  7. height="200"
  8. width="200"
  9. src="https://cdn.vuetifyjs.com/images/cards/store.jpg"
  10. ></v-img>
  11. </v-col>
  12. <v-col
  13. cols="auto"
  14. class="text-center pl-0"
  15. >
  16. <v-row
  17. class="flex-column ma-0 fill-height"
  18. justify="center"
  19. >
  20. <v-col class="px-0">
  21. <v-btn icon>
  22. <v-icon>mdi-heart</v-icon>
  23. </v-btn>
  24. </v-col>
  25. <v-col class="px-0">
  26. <v-btn icon>
  27. <v-icon>mdi-bookmark</v-icon>
  28. </v-btn>
  29. </v-col>
  30. <v-col class="px-0">
  31. <v-btn icon>
  32. <v-icon>mdi-share-variant</v-icon>
  33. </v-btn>
  34. </v-col>
  35. </v-row>
  36. </v-col>
  37. </v-row>
  38. </v-container>
  39. </v-card>
  40. </template>

Cards(卡片) - 图4

信息卡片

卡片是更详细信息的入口点。为简洁起见,请确保限制用户可以执行的操作数量。

template


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="344"
  5. >
  6. <v-card-text>
  7. <div>Word of the Day</div>
  8. <p class="display-1 text--primary">
  9. be•nev•o•lent
  10. </p>
  11. <p>adjective</p>
  12. <div class="text--primary">
  13. well meaning and kindly.<br>
  14. "a benevolent smile"
  15. </div>
  16. </v-card-text>
  17. <v-card-actions>
  18. <v-btn
  19. text
  20. color="deep-purple accent-4"
  21. >
  22. Learn More
  23. </v-btn>
  24. </v-card-actions>
  25. </v-card>
  26. </template>

Cards(卡片) - 图5

带文本的媒体

使用布局系统,我们可以在背景中的任何地方添加自定义文本。

template


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="400"
  5. >
  6. <v-img
  7. class="white--text align-end"
  8. height="200px"
  9. src="https://cdn.vuetifyjs.com/images/cards/docks.jpg"
  10. >
  11. <v-card-title>Top 10 Australian beaches</v-card-title>
  12. </v-img>
  13. <v-card-subtitle class="pb-0">Number 10</v-card-subtitle>
  14. <v-card-text class="text--primary">
  15. <div>Whitehaven Beach</div>
  16. <div>Whitsunday Island, Whitsunday Islands</div>
  17. </v-card-text>
  18. <v-card-actions>
  19. <v-btn
  20. color="orange"
  21. text
  22. >
  23. Share
  24. </v-btn>
  25. <v-btn
  26. color="orange"
  27. text
  28. >
  29. Explore
  30. </v-btn>
  31. </v-card-actions>
  32. </v-card>
  33. </template>

Cards(卡片) - 图6

栅格

使用栅格,您可以创建美丽的布局。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="500"
  5. >
  6. <v-system-bar
  7. color="indigo darken-2"
  8. dark
  9. >
  10. <v-spacer></v-spacer>
  11. <v-icon>mdi-window-minimize</v-icon>
  12. <v-icon>mdi-window-maximize</v-icon>
  13. <v-icon>mdi-close</v-icon>
  14. </v-system-bar>
  15. <v-toolbar
  16. color="indigo"
  17. dark
  18. >
  19. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  20. <v-toolbar-title>Discover</v-toolbar-title>
  21. <v-spacer></v-spacer>
  22. <v-btn icon>
  23. <v-icon>mdi-magnify</v-icon>
  24. </v-btn>
  25. </v-toolbar>
  26. <v-container fluid>
  27. <v-row dense>
  28. <v-col
  29. v-for="card in cards"
  30. :key="card.title"
  31. :cols="card.flex"
  32. >
  33. <v-card>
  34. <v-img
  35. :src="card.src"
  36. class="white--text align-end"
  37. gradient="to bottom, rgba(0,0,0,.1), rgba(0,0,0,.5)"
  38. height="200px"
  39. >
  40. <v-card-title v-text="card.title"></v-card-title>
  41. </v-img>
  42. <v-card-actions>
  43. <v-spacer></v-spacer>
  44. <v-btn icon>
  45. <v-icon>mdi-heart</v-icon>
  46. </v-btn>
  47. <v-btn icon>
  48. <v-icon>mdi-bookmark</v-icon>
  49. </v-btn>
  50. <v-btn icon>
  51. <v-icon>mdi-share-variant</v-icon>
  52. </v-btn>
  53. </v-card-actions>
  54. </v-card>
  55. </v-col>
  56. </v-row>
  57. </v-container>
  58. </v-card>
  59. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. cards: [
  5. { title: 'Pre-fab homes', src: 'https://cdn.vuetifyjs.com/images/cards/house.jpg', flex: 12 },
  6. { title: 'Favorite road trips', src: 'https://cdn.vuetifyjs.com/images/cards/road.jpg', flex: 6 },
  7. { title: 'Best airlines', src: 'https://cdn.vuetifyjs.com/images/cards/plane.jpg', flex: 6 },
  8. ],
  9. }),
  10. }
  11. </script>

Cards(卡片) - 图7

水平的卡片

使用v-flex,您可以创建自定义的水平卡片。使用contain属性来缩小v-card-media以适应容器内部,而不是覆盖。

template script


  1. <template>
  2. <v-card
  3. max-width="400"
  4. class="mx-auto"
  5. >
  6. <v-system-bar
  7. color="pink darken-2"
  8. dark
  9. >
  10. <v-spacer></v-spacer>
  11. <v-icon>mdi-window-minimize</v-icon>
  12. <v-icon>mdi-window-maximize</v-icon>
  13. <v-icon>mdi-close</v-icon>
  14. </v-system-bar>
  15. <v-app-bar
  16. dark
  17. color="pink"
  18. >
  19. <v-app-bar-nav-icon></v-app-bar-nav-icon>
  20. <v-toolbar-title>My Music</v-toolbar-title>
  21. <v-spacer></v-spacer>
  22. <v-btn icon>
  23. <v-icon>mdi-magnify</v-icon>
  24. </v-btn>
  25. </v-app-bar>
  26. <v-container>
  27. <v-row dense>
  28. <v-col cols="12">
  29. <v-card
  30. color="#385F73"
  31. dark
  32. >
  33. <v-card-title class="headline">Unlimited music now</v-card-title>
  34. <v-card-subtitle>Listen to your favorite artists and albums whenever and wherever, online and offline.</v-card-subtitle>
  35. <v-card-actions>
  36. <v-btn text>Listen Now</v-btn>
  37. </v-card-actions>
  38. </v-card>
  39. </v-col>
  40. <v-col
  41. v-for="(item, i) in items"
  42. :key="i"
  43. cols="12"
  44. >
  45. <v-card
  46. :color="item.color"
  47. dark
  48. >
  49. <div class="d-flex flex-no-wrap justify-space-between">
  50. <div>
  51. <v-card-title
  52. class="headline"
  53. v-text="item.title"
  54. ></v-card-title>
  55. <v-card-subtitle v-text="item.artist"></v-card-subtitle>
  56. </div>
  57. <v-avatar
  58. class="ma-3"
  59. size="125"
  60. tile
  61. >
  62. <v-img :src="item.src"></v-img>
  63. </v-avatar>
  64. </div>
  65. </v-card>
  66. </v-col>
  67. </v-row>
  68. </v-container>
  69. </v-card>
  70. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. items: [
  5. {
  6. color: '#1F7087',
  7. src: 'https://cdn.vuetifyjs.com/images/cards/foster.jpg',
  8. title: 'Supermodel',
  9. artist: 'Foster the People',
  10. },
  11. {
  12. color: '#952175',
  13. src: 'https://cdn.vuetifyjs.com/images/cards/halcyon.png',
  14. title: 'Halcyon Days',
  15. artist: 'Ellie Goulding',
  16. },
  17. ],
  18. }),
  19. }
  20. </script>

Cards(卡片) - 图8

Vue Jobs

Sign up and post a job or create your personalized developer profile at vuejobs.com.

ads by Vuetify

](https://vuejobs.com/?ref=vuetifyjs.com&ref=vuetify)

自定义操作

使用简单的条件,您可以轻松添加隐藏的补充文本,直到被打开。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="344"
  5. >
  6. <v-img
  7. src="https://cdn.vuetifyjs.com/images/cards/sunshine.jpg"
  8. height="200px"
  9. ></v-img>
  10. <v-card-title>
  11. Top western road trips
  12. </v-card-title>
  13. <v-card-subtitle>
  14. 1,000 miles of wonder
  15. </v-card-subtitle>
  16. <v-card-actions>
  17. <v-btn text>Share</v-btn>
  18. <v-btn
  19. color="purple"
  20. text
  21. >
  22. Explore
  23. </v-btn>
  24. <v-spacer></v-spacer>
  25. <v-btn
  26. icon
  27. @click="show = !show"
  28. >
  29. <v-icon>{{ show ? 'mdi-chevron-up' : 'mdi-chevron-down' }}</v-icon>
  30. </v-btn>
  31. </v-card-actions>
  32. <v-expand-transition>
  33. <div v-show="show">
  34. <v-divider></v-divider>
  35. <v-card-text>
  36. I'm a thing. But, like most politicians, he promised more than he could deliver. You won't have time for sleeping, soldier, not with all the bed making you'll be doing. Then we'll go with that data file! Hey, you add a one and two zeros to that or we walk! You're going to do his laundry? I've got to find a way to escape.
  37. </v-card-text>
  38. </div>
  39. </v-expand-transition>
  40. </v-card>
  41. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. show: false,
  5. }),
  6. }
  7. </script>

Cards(卡片) - 图9

Twitter 卡片

v-card 组件有多个子组件帮助您建立复杂的示例,而不必担心间隔。此示例由 v-card-titlev-card-textv-card-actions 组件组成。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. color="#26c6da"
  5. dark
  6. max-width="400"
  7. >
  8. <v-card-title>
  9. <v-icon
  10. large
  11. left
  12. >
  13. mdi-twitter
  14. </v-icon>
  15. <span class="title font-weight-light">Twitter</span>
  16. </v-card-title>
  17. <v-card-text class="headline font-weight-bold">
  18. "Turns out semicolon-less style is easier and safer in TS because most gotcha edge cases are type invalid as well."
  19. </v-card-text>
  20. <v-card-actions>
  21. <v-list-item class="grow">
  22. <v-list-item-avatar color="grey darken-3">
  23. <v-img
  24. class="elevation-6"
  25. src="https://avataaars.io/?avatarStyle=Transparent&topType=ShortHairShortCurly&accessoriesType=Prescription02&hairColor=Black&facialHairType=Blank&clotheType=Hoodie&clotheColor=White&eyeType=Default&eyebrowType=DefaultNatural&mouthType=Default&skinColor=Light"
  26. ></v-img>
  27. </v-list-item-avatar>
  28. <v-list-item-content>
  29. <v-list-item-title>Evan You</v-list-item-title>
  30. </v-list-item-content>
  31. <v-row
  32. align="center"
  33. justify="end"
  34. >
  35. <v-icon class="mr-1">mdi-heart</v-icon>
  36. <span class="subheading mr-2">256</span>
  37. <span class="mr-1">·</span>
  38. <v-icon class="mr-1">mdi-share-variant</v-icon>
  39. <span class="subheading">45</span>
  40. </v-row>
  41. </v-list-item>
  42. </v-card-actions>
  43. </v-card>
  44. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. //
  5. }),
  6. }
  7. </script>

Cards(卡片) - 图10

正在加载的卡片

在处理用户动作时,可以将卡片设置为加载状态。这将禁用进一步的操作,并提供具有不确定的 v-progress-linear 的可视反馈。

template script


  1. <template>
  2. <v-card
  3. :loading="loading"
  4. class="mx-auto my-12"
  5. max-width="374"
  6. >
  7. <v-img
  8. height="250"
  9. src="https://cdn.vuetifyjs.com/images/cards/cooking.png"
  10. ></v-img>
  11. <v-card-title>Cafe Badilico</v-card-title>
  12. <v-card-text>
  13. <v-row
  14. align="center"
  15. class="mx-0"
  16. >
  17. <v-rating
  18. :value="4.5"
  19. color="amber"
  20. dense
  21. half-increments
  22. readonly
  23. size="14"
  24. ></v-rating>
  25. <div class="grey--text ml-4">4.5 (413)</div>
  26. </v-row>
  27. <div class="my-4 subtitle-1">
  28. $ • Italian, Cafe
  29. </div>
  30. <div>Small plates, salads & sandwiches - an intimate setting with 12 indoor seats plus patio seating.</div>
  31. </v-card-text>
  32. <v-divider class="mx-4"></v-divider>
  33. <v-card-title>Tonight's availability</v-card-title>
  34. <v-card-text>
  35. <v-chip-group
  36. v-model="selection"
  37. active-class="deep-purple accent-4 white--text"
  38. column
  39. >
  40. <v-chip>5:30PM</v-chip>
  41. <v-chip>7:30PM</v-chip>
  42. <v-chip>8:00PM</v-chip>
  43. <v-chip>9:00PM</v-chip>
  44. </v-chip-group>
  45. </v-card-text>
  46. <v-card-actions>
  47. <v-btn
  48. color="deep-purple lighten-2"
  49. text
  50. @click="reserve"
  51. >
  52. Reserve
  53. </v-btn>
  54. </v-card-actions>
  55. </v-card>
  56. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. loading: false,
  5. selection: 1,
  6. }),
  7. methods: {
  8. reserve () {
  9. this.loading = true
  10. setTimeout(() => (this.loading = false), 2000)
  11. },
  12. },
  13. }
  14. </script>

Cards(卡片) - 图11

天气卡片

通过使用 v-list-itemsv-slider,我们可以创建独特的天气卡片。列表组件确保我们具有一致的间距和功能,而滑块组件允许我们向用户提供有用的选择界面。

template script


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="400"
  5. >
  6. <v-list-item two-line>
  7. <v-list-item-content>
  8. <v-list-item-title class="headline">San Francisco</v-list-item-title>
  9. <v-list-item-subtitle>Mon, 12:30 PM, Mostly sunny</v-list-item-subtitle>
  10. </v-list-item-content>
  11. </v-list-item>
  12. <v-card-text>
  13. <v-row align="center">
  14. <v-col class="display-3" cols="6">
  15. 23&deg;C
  16. </v-col>
  17. <v-col cols="6">
  18. <v-img
  19. src="https://cdn.vuetifyjs.com/images/cards/sun.png"
  20. alt="Sunny image"
  21. width="92"
  22. ></v-img>
  23. </v-col>
  24. </v-row>
  25. </v-card-text>
  26. <v-list-item>
  27. <v-list-item-icon>
  28. <v-icon>mdi-send</v-icon>
  29. </v-list-item-icon>
  30. <v-list-item-subtitle>23 km/h</v-list-item-subtitle>
  31. </v-list-item>
  32. <v-list-item>
  33. <v-list-item-icon>
  34. <v-icon>mdi-cloud-download</v-icon>
  35. </v-list-item-icon>
  36. <v-list-item-subtitle>48%</v-list-item-subtitle>
  37. </v-list-item>
  38. <v-slider
  39. v-model="time"
  40. :max="6"
  41. :tick-labels="labels"
  42. class="mx-4"
  43. ticks
  44. ></v-slider>
  45. <v-list class="transparent">
  46. <v-list-item
  47. v-for="item in forecast"
  48. :key="item.day"
  49. >
  50. <v-list-item-title>{{ item.day }}</v-list-item-title>
  51. <v-list-item-icon>
  52. <v-icon>{{ item.icon }}</v-icon>
  53. </v-list-item-icon>
  54. <v-list-item-subtitle class="text-right">
  55. {{ item.temp }}
  56. </v-list-item-subtitle>
  57. </v-list-item>
  58. </v-list>
  59. <v-divider></v-divider>
  60. <v-card-actions>
  61. <v-btn text>Full Report</v-btn>
  62. </v-card-actions>
  63. </v-card>
  64. </template>
  1. <script>
  2. export default {
  3. data () {
  4. return {
  5. labels: ['SU', 'MO', 'TU', 'WED', 'TH', 'FR', 'SA'],
  6. time: 0,
  7. forecast: [
  8. { day: 'Tuesday', icon: 'mdi-white-balance-sunny', temp: '24\xB0/12\xB0' },
  9. { day: 'Wednesday', icon: 'mdi-white-balance-sunny', temp: '22\xB0/14\xB0' },
  10. { day: 'Thursday', icon: 'mdi-cloud', temp: '25\xB0/15\xB0' },
  11. ],
  12. }
  13. },
  14. }
  15. </script>

Cards(卡片) - 图12

高级版

使用 v-list-itemv-img 允许我们在高级设置中创建唯一的卡片布局

template


  1. <template>
  2. <v-card
  3. max-width="344"
  4. class="mx-auto"
  5. >
  6. <v-list-item>
  7. <v-list-item-avatar color="grey"></v-list-item-avatar>
  8. <v-list-item-content>
  9. <v-list-item-title class="headline">Our Changing Planet</v-list-item-title>
  10. <v-list-item-subtitle>by Kurt Wagner</v-list-item-subtitle>
  11. </v-list-item-content>
  12. </v-list-item>
  13. <v-img
  14. src="https://cdn.vuetifyjs.com/images/cards/mountain.jpg"
  15. height="194"
  16. ></v-img>
  17. <v-card-text>
  18. Visit ten places on our planet that are undergoing the biggest changes today.
  19. </v-card-text>
  20. <v-card-actions>
  21. <v-btn
  22. text
  23. color="deep-purple accent-4"
  24. >
  25. Read
  26. </v-btn>
  27. <v-btn
  28. text
  29. color="deep-purple accent-4"
  30. >
  31. Bookmark
  32. </v-btn>
  33. <v-spacer></v-spacer>
  34. <v-btn icon>
  35. <v-icon>mdi-heart</v-icon>
  36. </v-btn>
  37. <v-btn icon>
  38. <v-icon>mdi-share-variant</v-icon>
  39. </v-btn>
  40. </v-card-actions>
  41. </v-card>
  42. </template>

Cards(卡片) - 图13