Skip to content

Image Component

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

📌Platform Differences

APP(vue)H5WeChat Mini ProgramAlipay Mini Program

🏯Basic Usage Example

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

Set 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>

Set Shape

  • Set the image shape via the shape prop
    • circle: circular
    • 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>

Preview 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>

Set 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

ParameterDescriptionTypeDefault
srcImage URL, strongly recommended to use an absolute or network pathstring-
modeCrop mode, see image component for detailsstringaspectFill
widthWidth, default unit px for numeric valuesstring|number200
heightHeight, default unit px for numeric valuesstring|number150
shapeImage shape[1]circle|squaresquare
radiusBorder radius, default unit px for numeric valuesstring|number0
lazyLoadWhether to enable lazy loading, only effective on WeChat Mini Program, App, Baidu Mini Program, and ByteDance Mini Programbooleantrue
showMenuByLongPressWhether to enable the mini program code recognition menu on long press, only effective on WeChat Mini Programbooleantrue
loadingIconLoading icon or small imagestringLOADING
errorIconError 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 when loading images on dark pages to blend with the background colorstring-
indistinctBlur the image, applies a blur style to the imagebooleanfalse
previewImageWhether to enable image previewbooleanfalse
customStyleCustom external styles to be appliedCSSProperties-
customClassCustom external class namestring-

Events

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

Slots

Slot NameDescriptionReceived Value
loadingCustom loading indicator content-
errorCustom failure indicator content-
03:29

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