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 查看。

html
<vd-image
  src="http://vital-design.cn/ui/static/exh-1.jpg"
  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>

API

Props

参数说明类型默认值
src图片地址string-
mode填充模式ImageMode'scaleToFill'
width宽度string | number-
height高度string | number-
radius边框半径string | number-
show-loading是否展示加载中提示booleantrue
loading-type加载中类型LoadingType'spinner'
show-error是否展示加载失败提示booleantrue
error-icon加载失败图标IconsName'pic-error'
icon-size加载中、加载错误图标大小number | string30
lazy-load是否开启图片懒加载booleanfalse
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