Skip to content

Image 图片 ​

介绍 ​

展示图片,支持图片懒加载、加载中提示、加载失败提示。

基础用法 ​

与 image 标签一致,通过 src 属性设置图片地址。

html
<vd-image
  src="http://vital-design.cn/ui/static/exh-1.jpg"
  width="100"
  height="100"
/>

填充模式 ​

通过 mode 属性设置图片填充模式,具体可前往 uniapp 官网 Image 查看。

widthFix / heightFix 下,对应的 height / width 仅作加载前占位;加载完成后根节点该方向改为 auto,由原生模式按图片比例撑开。

html
<vd-image
  src="http://vital-design.cn/ui/static/exh-1.jpg"
  width="100%"
  height="100"
  mode="widthFix"
/>

加载中提示 ​

图片加载/未定义时,会展示 loading 加载中,支持通过 loading 插槽自定义内容。

html
<vd-image width="100" height="100" />

<vd-image width="100" height="100">
  <template #loading>加载中...</template>
</vd-image>

加载失败提示 ​

图片加载失败时,会展示 error 加载失败,支持通过 error 插槽自定义内容。

html
<vd-image src="xx" width="100" height="100" />
<vd-image src="xx" width="100" height="100">
  <template #error>加载失败</template>
</vd-image>

懒加载 ​

开启 lazy-load 后,图片进入视口才赋真实 src 并开始请求(基于可见监听,相对页面视口)。适用于长列表;自定义滚动容器内若监听不到,可关闭懒加载或保证节点相对视口可相交。

html
<vd-image
  lazy-load
  src="http://vital-design.cn/ui/static/exh-1.jpg"
  width="100"
  height="100"
/>

淡入展示 ​

默认开启 fade-show:图片加载完成后淡入。传 false 可关闭。

html
<vd-image
  :fade-show="false"
  src="http://vital-design.cn/ui/static/exh-1.jpg"
  width="100"
  height="100"
/>

API ​

Props ​

参数说明类型默认值
src图片地址string-
mode填充模式ImageMode'scaleToFill'
width宽度;heightFix 时加载前可作占位string | number-
height高度;widthFix 时加载前可作占位string | number-
radius边框半径string | number-
show-loading是否展示加载中提示booleantrue
loading-type加载中类型LoadingType'spinner'
show-error是否展示加载失败提示booleantrue
error-icon加载失败图标IconName'pic-error'
icon-size加载中、加载错误图标大小number | string30
lazy-load是否开启懒加载(进视口后再请求)booleanfalse
fade-show图片加载完成后是否淡入展示booleantrue
webp不支持 webp 时是否单独启用(仅网络资源)booleanfalse
draggable是否能拖动图片booleantrue
show-menu-by-longpress开启长按图片显示识别小程序码菜单booleanfalse

代替原始 Props ​

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events ​

事件名说明回调参数
click点击时触发MouseEvent
click-image点击图片时触发MouseEvent
load图片加载完成时触发Event
error图片加载失败时触发Event

Slots ​

名称说明
default图片下方内容
loading加载中
error加载失败

赣ICP备2025061025号-1