头像

v-avatar 组件通常用于显示用户个人资料的圆形图片。该组件将允许你动态调整大小并添加响应图像,图标和文本的边框半径。tile 变量可用来显示方形头像。

用例

头像以最简单的形式在圆形容器中显示内容。

Avatars(头像) - 图1

API

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

Avatars(头像) - 图2

示例

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

大小

size 属性允许你定义 v-avatar 的高度和宽度。这个属性以 1 的长宽比均匀缩放。heightwidth 属性将会覆盖这个属性。

template


  1. <template>
  2. <v-row justify="space-around">
  3. <v-avatar color="indigo" size="36">
  4. <span class="white--text headline">36</span>
  5. </v-avatar>
  6. <v-avatar color="teal" size="48">
  7. <span class="white--text headline">48</span>
  8. </v-avatar>
  9. <v-avatar color="orange" size="62">
  10. <span class="white--text headline">62</span>
  11. </v-avatar>
  12. </v-row>
  13. </template>

Avatars(头像) - 图3

平铺

tile 属性会移除圆形边框,为你提供简单的正方形 v-avatar。

template


  1. <template>
  2. <div class="text-center">
  3. <v-avatar tile color="blue">
  4. <v-icon dark>mdi-alarm</v-icon>
  5. </v-avatar>
  6. </div>
  7. </template>

Avatars(头像) - 图4

默认插槽

v-avatar 的默认插槽将接受 v-icon 组件、图像或文本。混合并匹配这些元素来创建一个独一无二的东西。

template


  1. <template>
  2. <v-row justify="space-around">
  3. <v-avatar color="indigo">
  4. <v-icon dark>mdi-account-circle</v-icon>
  5. </v-avatar>
  6. <v-avatar>
  7. <img
  8. src="https://cdn.vuetifyjs.com/images/john.jpg"
  9. alt="John"
  10. >
  11. </v-avatar>
  12. <v-avatar color="red">
  13. <span class="white--text headline">CJ</span>
  14. </v-avatar>
  15. </v-row>
  16. </template>

Avatars(头像) - 图5

Black Vuetify Cap

An updated classic that won’t break the bank! This hat perfectly combines style and function.

ads by Vuetify

](https://store.vuetifyjs.com/product/black-vuetify-logo-cap?ref=vuetifyjs.com)

个人资料卡

使用 tile 属性,我们可以创建一个光滑的内衬型卡。

template


  1. <template>
  2. <v-card
  3. class="mx-auto"
  4. max-width="434"
  5. tile
  6. >
  7. <v-img
  8. height="100%"
  9. src="https://cdn.vuetifyjs.com/images/cards/server-room.jpg"
  10. >
  11. <v-row
  12. align="end"
  13. class="fill-height"
  14. >
  15. <v-col
  16. align-self="start"
  17. class="pa-0"
  18. cols="12"
  19. >
  20. <v-avatar
  21. class="profile"
  22. color="grey"
  23. size="164"
  24. tile
  25. >
  26. <v-img src="https://cdn.vuetifyjs.com/images/profiles/marcus.jpg"></v-img>
  27. </v-avatar>
  28. </v-col>
  29. <v-col class="py-0">
  30. <v-list-item
  31. color="rgba(0, 0, 0, .4)"
  32. dark
  33. >
  34. <v-list-item-content>
  35. <v-list-item-title class="title">Marcus Obrien</v-list-item-title>
  36. <v-list-item-subtitle>Network Engineer</v-list-item-subtitle>
  37. </v-list-item-content>
  38. </v-list-item>
  39. </v-col>
  40. </v-row>
  41. </v-img>
  42. </v-card>
  43. </template>

Avatars(头像) - 图6

高级用法

将头像与其他组件组合在一起,你就可以构建漂亮的用户界面。

template script


  1. <template>
  2. <v-container fluid>
  3. <v-row justify="center">
  4. <v-subheader>Today</v-subheader>
  5. <v-expansion-panels popout>
  6. <v-expansion-panel
  7. v-for="(message, i) in messages"
  8. :key="i"
  9. hide-actions
  10. >
  11. <v-expansion-panel-header>
  12. <v-row
  13. align="center"
  14. class="spacer"
  15. no-gutters
  16. >
  17. <v-col
  18. cols="4"
  19. sm="2"
  20. md="1"
  21. >
  22. <v-avatar
  23. size="36px"
  24. >
  25. <img
  26. v-if="message.avatar"
  27. alt="Avatar"
  28. src="https://avatars0.githubusercontent.com/u/9064066?v=4&s=460"
  29. >
  30. <v-icon
  31. v-else
  32. :color="message.color"
  33. v-text="message.icon"
  34. ></v-icon>
  35. </v-avatar>
  36. </v-col>
  37. <v-col
  38. class="hidden-xs-only"
  39. sm="5"
  40. md="3"
  41. >
  42. <strong v-html="message.name"></strong>
  43. <span
  44. v-if="message.total"
  45. class="grey--text"
  46. >
  47. &nbsp;({{ message.total }})
  48. </span>
  49. </v-col>
  50. <v-col
  51. class="text-no-wrap"
  52. cols="5"
  53. sm="3"
  54. >
  55. <v-chip
  56. v-if="message.new"
  57. :color="`${message.color} lighten-4`"
  58. class="ml-0 mr-2 black--text"
  59. label
  60. small
  61. >
  62. {{ message.new }} new
  63. </v-chip>
  64. <strong v-html="message.title"></strong>
  65. </v-col>
  66. <v-col
  67. v-if="message.excerpt"
  68. class="grey--text text-truncate hidden-sm-and-down"
  69. >
  70. &mdash;
  71. {{ message.excerpt }}
  72. </v-col>
  73. </v-row>
  74. </v-expansion-panel-header>
  75. <v-expansion-panel-content>
  76. <v-divider></v-divider>
  77. <v-card-text v-text="lorem"></v-card-text>
  78. </v-expansion-panel-content>
  79. </v-expansion-panel>
  80. </v-expansion-panels>
  81. </v-row>
  82. </v-container>
  83. </template>
  1. <script>
  2. export default {
  3. data: () => ({
  4. messages: [
  5. {
  6. avatar: 'https://avatars0.githubusercontent.com/u/9064066?v=4&s=460',
  7. name: 'John Leider',
  8. title: 'Welcome to Vuetify.js!',
  9. excerpt: 'Thank you for joining our community...',
  10. },
  11. {
  12. color: 'red',
  13. icon: 'people',
  14. name: 'Social',
  15. new: 1,
  16. total: 3,
  17. title: 'Twitter',
  18. },
  19. {
  20. color: 'teal',
  21. icon: 'local_offer',
  22. name: 'Promos',
  23. new: 2,
  24. total: 4,
  25. title: 'Shop your way',
  26. exceprt: 'New deals available, Join Today',
  27. },
  28. ],
  29. lorem: 'Lorem ipsum dolor sit amet, at aliquam vivendum vel, everti delicatissimi cu eos. Dico iuvaret debitis mel an, et cum zril menandri. Eum in consul legimus accusam. Ea dico abhorreant duo, quo illum minimum incorrupte no, nostro voluptaria sea eu. Suas eligendi ius at, at nemore equidem est. Sed in error hendrerit, in consul constituam cum.',
  30. }),
  31. }
  32. </script>

Avatars(头像) - 图7