# Avatar 頭像
頭像展示。圖片、圖示、文字三種形態按優先級回退:src 失敗時依次取 icon、text 首字。
頭像
<template>
<div class="demo-col">
<div class="demo-row" style="gap: 24px; flex-wrap: wrap">
<LhAvatar :src="src" alt="溪山行旅圖局部" />
<LhAvatar :src="src" shape="square" />
<LhAvatar text="范寬" />
<LhAvatar icon="lh-icon-user" />
<LhAvatar text="北宋" shape="square" size="large" />
<LhAvatar text="郭" size="small" />
<LhAvatar text="自訂" :size="64" fit="cover" />
</div>
<p class="demo-note">圖片載入失敗時回退到 alt / 圖示 / 文字</p>
<div class="demo-row" style="gap: 24px; flex-wrap: wrap">
<LhAvatar src="https://placeholder.lhgb.top/broken.png" alt="載入失敗" />
<LhAvatar src="https://placeholder.lhgb.top/broken.png" icon="lh-icon-user" alt="回退圖示" />
</div>
</div>
</template>
<script>
export default {
data: () => ({
src: 'data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20width=%2764%27%20height=%2764%27%3E%3Crect%20width=%2764%27%20height=%2764%27%20fill=%27%23e8e2d5%27/%3E%3Cpath%20d=%27M0%2046%20Q16%2032%2032%2046%20T64%2046%20V64%20H0%20Z%27%20fill=%27%23c9c2b2%27/%3E%3Ctext%20x=%2750%%27%20y=%2726%27%20font-size=%2726%27%20fill=%27%232b4c7c%27%20text-anchor=%27middle%27%20font-family=%27serif%27%3E%E5%B1%B1%3C/text%3E%3C/svg%3E',
}),
}
</script>
# Props
| 屬性 | 說明 | 類型 | 預設值 |
|---|---|---|---|
| src | 圖片位址;為空時依次回退到圖示、文字 | string | — |
| alt | 圖片載入失敗的替代文字,同時作為 alt | string | — |
| icon | 圖示類別名(src 為空或載入失敗時展示) | string | — |
| text | 文字頭像內容(src 與 icon 都缺省時取首字展示) | string | — |
| shape | 頭像形狀 | 'circle' \| 'square' | 'circle' |
| size | 頭像大小 | 'small' \| 'default' \| 'large' \| number | 'default' |
| fit | 圖片載入模式 | 'fill' \| 'contain' \| 'cover' \| 'none' \| 'scale-down' | 'cover' |
| sx | sx 快速佈局屬性 | — | — |
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537