Image 图片
WebH5
图片。支持 object-fit 填充、固定尺寸、圆角、懒加载、加载中/失败占位,以及点击全屏预览(内置 ImagePreview)。
何时使用
需要控制填充、占位、懒加载或点击预览的图片展示场景。
何时不使用
纯装饰小图标用 Icon;头像用 Avatar。
Props
| 名称 | 类型 | 默认值 | 说明 |
|---|---|---|---|
src | string | "''" | 图片地址 |
alt | string | "''" | 替代文本 |
fit | string:'fill' | 'contain' | 'cover' | 'none' | 'scale-down' | "cover" | 填充模式,同原生 object-fit |
width | string | number | "-" | 宽度,数字按 px 处理 |
height | string | number | "-" | 高度,数字按 px 处理 |
radius | boolean | false | 圆角(radius-md) |
lazy | boolean | false | IntersectionObserver 懒加载;环境不支持时降级为立即加载 |
preview | boolean | false | 点击调起全屏预览(ImagePreview) |
Slots
| 名称 | 说明 |
|---|---|
error | 加载失败占位,默认破裂图片 SVG |
placeholder | 加载中占位,默认 bg-soft 底色块 |
示例
基础(圆角)
示例加载中…
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23667eea'/%3E%3Cstop%20offset='1'%20stop-color='%23764ba2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3Ccircle%20cx='318'%20cy='72'%20r='34'%20fill='rgba(255,255,255,0.55)'/%3E%3Cpath%20d='M0%20300%20L130%20160%20L230%20242%20L326%20172%20L400%20232%20L400%20300%20Z'%20fill='rgba(255,255,255,0.28)'/%3E%3C/svg%3E" alt="产品主图" width="120" height="120" radius />填充模式(cover / contain / fill)
示例加载中…
<div style="display:flex;gap:12px;">
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23667eea'/%3E%3Cstop%20offset='1'%20stop-color='%23764ba2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3Ccircle%20cx='318'%20cy='72'%20r='34'%20fill='rgba(255,255,255,0.55)'/%3E%3Cpath%20d='M0%20300%20L130%20160%20L230%20242%20L326%20172%20L400%20232%20L400%20300%20Z'%20fill='rgba(255,255,255,0.28)'/%3E%3C/svg%3E" fit="cover" alt="cover" width="104" height="104" radius />
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23667eea'/%3E%3Cstop%20offset='1'%20stop-color='%23764ba2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3Ccircle%20cx='318'%20cy='72'%20r='34'%20fill='rgba(255,255,255,0.55)'/%3E%3Cpath%20d='M0%20300%20L130%20160%20L230%20242%20L326%20172%20L400%20232%20L400%20300%20Z'%20fill='rgba(255,255,255,0.28)'/%3E%3C/svg%3E" fit="contain" alt="contain" width="104" height="104" radius />
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23667eea'/%3E%3Cstop%20offset='1'%20stop-color='%23764ba2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3Ccircle%20cx='318'%20cy='72'%20r='34'%20fill='rgba(255,255,255,0.55)'/%3E%3Cpath%20d='M0%20300%20L130%20160%20L230%20242%20L326%20172%20L400%20232%20L400%20300%20Z'%20fill='rgba(255,255,255,0.28)'/%3E%3C/svg%3E" fit="fill" alt="fill" width="104" height="104" radius />
</div>点击全屏预览
示例加载中…
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23f6d365'/%3E%3Cstop%20offset='1'%20stop-color='%23fda085'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3Ccircle%20cx='318'%20cy='72'%20r='34'%20fill='rgba(255,255,255,0.55)'/%3E%3Cpath%20d='M0%20300%20L130%20160%20L230%20242%20L326%20172%20L400%20232%20L400%20300%20Z'%20fill='rgba(255,255,255,0.28)'/%3E%3C/svg%3E" alt="点击预览" preview width="200" height="120" radius />加载失败占位
示例加载中…
<Image src="/images/not-exist.png" alt="加载失败示例" width="120" height="120" radius />不同尺寸组合
示例加载中…
<div style="display:flex;gap:12px;align-items:center;">
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%2384fab0'/%3E%3Cstop%20offset='1'%20stop-color='%238fd3f4'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3C/svg%3E" alt="小图" width="48" height="48" radius />
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23f6d365'/%3E%3Cstop%20offset='1'%20stop-color='%23fda085'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3C/svg%3E" alt="中图" width="96" height="96" radius />
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23667eea'/%3E%3Cstop%20offset='1'%20stop-color='%23764ba2'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3C/svg%3E" alt="大图" width="160" height="160" radius />
</div>懒加载
示例加载中…
<Image src="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20width='400'%20height='300'%3E%3Cdefs%3E%3ClinearGradient%20id='g'%20x1='0'%20y1='0'%20x2='1'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%2384fab0'/%3E%3Cstop%20offset='1'%20stop-color='%238fd3f4'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20width='400'%20height='300'%20fill='url(%23g)'/%3E%3C/svg%3E" alt="懒加载图片" lazy width="200" height="120" radius />Playground
加载中…
cover
跨端版本
该组件同时提供 uni-app / uni-app X 实现(H5 / 微信小程序 / App),API 可能略有差异,见 uni-app 端 Image 文档(含手机预览)。