Avatar 头像 #
Avatar 组件可以用来代表人物或对象, 支持使用图片,图标或者文字作为 Avatar
基础用法 #
使用 shape
和 size
属性来设置 Avatar 的形状和大小。
输入 #
<demo src="../component/avatar.vue"></demo>
输出 #
circle
square
<template>
<el-row class="demo-avatar demo-basic">
<el-col :span="12">
<div class="sub-title">circle</div>
<div class="demo-basic--circle">
<div class="block">
<el-avatar :size="50" :src="circleUrl" />
</div>
<div v-for="size in sizeList" :key="size" class="block">
<el-avatar :size="size" :src="circleUrl" />
</div>
</div>
</el-col>
<el-col :span="12">
<div class="sub-title">square</div>
<div class="demo-basic--circle">
<div class="block">
<el-avatar shape="square" :size="50" :src="squareUrl" />
</div>
<div v-for="size in sizeList" :key="size" class="block">
<el-avatar shape="square" :size="size" :src="squareUrl" />
</div>
</div>
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import { reactive, toRefs } from "vue";
const state = reactive({
circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
squareUrl: "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png",
sizeList: ["small", "", "large"] as const,
});
const { circleUrl, squareUrl, sizeList } = toRefs(state);
</script>
<style scoped>
.demo-basic {
text-align: center;
}
.demo-basic .sub-title {
margin-bottom: 10px;
font-size: 14px;
color: var(--el-text-color-secondary);
}
.demo-basic .demo-basic--circle,
.demo-basic .demo-basic--square {
display: flex;
justify-content: space-between;
align-items: center;
}
.demo-basic .block:not(:last-child) {
border-right: 1px solid var(--el-border-color);
}
.demo-basic .block {
flex: 1;
}
.demo-basic .el-col:not(:last-child) {
border-right: 1px solid var(--el-border-color);
}
</style>
显示代码