Image

Updated at:

Introduction

The image component is a user interface (UI) element that displays image content. It supports image previews and lets you set the image source and related styles.

image

Configuration items

Category

Configuration

Example

Description

Content

Image source

The three modes for image resources.

URL

image

This takes effect when the image source is set to URL. The value is the link to the image.

System file

This takes effect when the image source is set to System file. The value is the image link. Select an image from the built-in resource files, or click the box below to upload a new one.

Memory object

image

This takes effect when the image source is set to Memory object. It can be associated with an upload component. For example: upload1.values?.[0]. This is used for scenarios where an actual upload is not required.

Hotspot configuration

Define specific areas on an image. Clicks in these areas trigger interactive behaviors and enhance the user experience.

Image description

The text to display when the image fails to load.

Fallback address on load failure

image

Displays a preset image placeholder when the image fails to load.

Progressive load

Enable Progressive load to improve user experience and avoid long waits for large images. It first shows a simplified preview, such as a low-resolution image, a solid color background, or a Low Quality Image Placeholder (LQIP). This optimizes the visual experience before the full image finishes loading.

Allow preview

Lets users click the image to open a pop-up and view a high-definition preview.

Preview configuration

Redefine the path for the preview image. The default is the current image resource.

Interaction

Hidden

Controls the default display state of the image component. When set to true, the component is hidden. For more information, see Common properties

Style

Height

The height of the component. For more information, see Common properties

Margin

For more information, see Common properties

Padding

Specifies how the image content should fit into the box defined by its height and width. For more information, see the object-fit property

  • Cover: The image fills the entire content box of the element while maintaining its aspect ratio.

  • Contain: The image is scaled to fit within the content box while maintaining its aspect ratio.

  • Stretch: The image completely fills the component box. If the aspect ratio of the image does not match the component box, the image is stretched to fit.

Image layout

Specifies the position of the image within the component when the fit mode is set to contain.

CSS style

Border radius

The border radius of the image component. For more information, see Common properties

Flip

image

The flip mode for the image. Supports horizontal and vertical flipping. The rotation point is the centroid of the image. For more information, see the rotate property

Properties and methods

Name

Type

Example

Description

mode

string

image1.mode

The image source.

src

string

image1.src

The link of the current image component.

file

object

image1.file

Read-only. The image file resource.

srcFile

object

image1.srcFile

Read-only. The image memory object.

fallback

string

image1.fallback

Read-only. Displays a preset image placeholder when the image fails to load.

placeholder

string

image1.placeholder

Read-only. The link to the image for progressive loading.

alt

string

image1.alt

Read-only. The text to display when the image fails to load.

preview

boolean

image1.preview

Read-only. Specifies whether the image can be clicked for a preview.

hotAreas

object

image1.hotAreas

Read-only. The hotspot configuration information for the image.

hidden

boolean

image1.hidden

Specifies whether the current component is hidden. For more information, see Common properties

setSrc

func

image1.setSrc('image_link')

Sets the image link to image_link.

clearSrc

func

image1.clearSrc()

Clears the image link.

setHidden

func

image1.setHidden(false)

Sets whether the image is hidden. The parameter can be true or false. For more information, see Common properties

clearHidden

func

image1.clearHidden()

Clears the hidden state of the image. For more information, see Common properties

Event callbacks

Configuration

Description

The event that is triggered when the image is clicked.

The event that is triggered when the image fails to load.

Scenario example

  • Product image display scenario
    • The product image is displayed in the area on the left.

      image