Skip to content

Image ​

图片容器:fit / radius / loading;加载失败可自定义 fallback。

基础 ​

耳机与唱片机
现场演出
vue
<script setup lang="ts">
import { HImage } from 'happier-ui'
</script>

<template>
  <h-image
    src="/cover.jpg"
    alt="封面"
    :width="120"
    :height="120"
    fit="cover"
    radius="md"
  />
</template>

失败 fallback ​

失败占位示例
vue
<h-image src="…" alt="失败占位示例" :width="96" :height="96">
  <template #fallback>
    <span aria-hidden="true">♫</span>
  </template>
</h-image>

API ​

Props ​

名称类型默认说明
srcstring—必填
altstring—必填;无障碍替代文本
widthstring | number—宽;数字为 px
heightstring | number—高;数字为 px
loading'eager' | 'lazy''lazy'原生 loading
fit'cover' | 'contain' | 'fill' | 'none' | 'scale-down''cover'object-fit
radius'none' | 'sm' | 'md' | 'lg' | 'full''md'圆角档位

Slots ​

名称说明
fallback加载失败时的占位内容

Emits ​

无。

无障碍 ​

  • alt 必填
  • fallback 为装饰时可用 aria-hidden;勿用 fallback 覆盖真实 alt 语义

MIT License