Skip to content

Image Component ​

This component is an enhanced version of the uni-app image component. In addition to inheriting all the original features, it also supports fade-in animation, loading indicators, load failure hints, border radius values, and shapes.

📌 Platform Differences ​

APP(vue)H5WeChat Mini ProgramAlipay Mini Program
✔✔✔✔

🏯 Basic Usage ​

html
<!-- Global usage -->
<hy-image
    src="https://q9.itc.cn/q_70/images03/20250211/6ee1b8e0f4704083ba715986c8c3795f.jpeg"
></hy-image>

Setting Size ​

  • Set the image width via the width prop
  • Set the image height via the height prop
html
<template>
    <hy-image
        src="https://q9.itc.cn/q_70/images03/20250211/6ee1b8e0f4704083ba715986c8c3795f.jpeg"
        width="100"
        height="100"
    ></hy-image>
</template>

Setting Border Radius ​

  • Set the image shape via the shape prop
    • circle: circle
    • square: square
html
<template>
    <hy-image
        src="https://q9.itc.cn/q_70/images03/20250211/6ee1b8e0f4704083ba715986c8c3795f.jpeg"
        width="100"
        height="100"
        shape="circle"
    ></hy-image>
</template>

Previewing Full-size Image ​

  • Set previewImage to true to enable full-size image preview
html
<template>
    <hy-image
        src="https://q9.itc.cn/q_70/images03/20250211/6ee1b8e0f4704083ba715986c8c3795f.jpeg"
        previewImage
    ></hy-image>
</template>

Setting Fade-in Effect ​

  • Set fade to true to enable the animation (true by default)
html
<template>
    <hy-image
        src="https://q9.itc.cn/q_70/images03/20250211/6ee1b8e0f4704083ba715986c8c3795f.jpeg"
        fade
    ></hy-image>
</template>

API ​

Props ​

PropDescriptionTypeDefault
srcImage URL. It is strongly recommended to use an absolute or network pathstring-
modeCrop mode. See image component for detailsstringaspectFill
widthWidth, px by default for numeric valuesstring|number200
heightHeight, px by default for numeric valuesstring|number150
shapeImage shape[1]circle|squaresquare
radiusBorder radius, px by default for numeric valuesstring|number0
lazyLoadWhether to lazy load. Only effective on WeChat Mini Program, App, Baidu Mini Program, and ByteDance Mini Programbooleantrue
showMenuByLongPressWhether to enable showing the mini program code recognition menu when long-pressing the image. Only effective on WeChat Mini Programbooleantrue
loadingIconLoading icon, or small imagestringLOADING
errorIconLoad failure icon, or small imagestringNOTICE
showLoadingWhether to show the loading icon or a custom slotbooleantrue
showErrorWhether to show the error icon or a custom slotbooleantrue
fadeWhether to enable the fade-in effectbooleantrue
webpOnly supports network resources. Only effective on WeChat Mini Programbooleanfalse
durationTransition duration used with the fade prop, in msnumber500
bgColorBackground color, used to blend with the background when loading images on dark pagesstring-
indistinctBlurred image, applies a blur style to the imagebooleanfalse
previewImageWhether to preview the imagebooleanfalse
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events ​

EventDescriptionCallback Parameters
clickTriggered when the image is clicked-
errorTriggered when the image fails to loaderr: error message
loadTriggered when the image loads successfullye

Slots ​

SlotDescriptionAccepted Values
loadingCustom loading hint content-
errorCustom failure hint content-

CSS Variables ​

VariableDescriptionDefault
--hy-image-widthDefault width250px
--hy-image-heightDefault height200px
--hy-image-placeholder-colorLoading/failure placeholder colorFollows --hy-text-color--grey
12:33
battery

  1. circle: both sides are semicircles; square: square ↩︎