Skip to content

Image

Displays image resources, with an optional built-in preview feature.

Basic Usage

Basic image

Fit Mode

object-fit variants

cover (crop to fill)

contain (fit fully)

Set object-fit via fit, then fix the image container size with ::part(image) to achieve the crop effect.

Placeholder and Fallback

Loading placeholder

With placeholder, a light-gray placeholder is shown until the image finishes loading, then it switches to the image.

Load failure fallback

Default failure placeholder

Custom fallback image

When the image fails to load, a "图片加载失败" placeholder is shown by default; the fallback attribute can specify a fallback image URL, and if the fallback also fails, it falls back to the placeholder text.

Preview

Click to preview (built-in overlay)

Click the image to open a full-screen preview overlay: the toolbar supports zoom in / out, rotate, and download; press Esc or click the mask to close. The close button is focused when opened, and focus is restored on close. Emits oas-preview (detail contains src).

API

Attributes

AttributeDescriptionTypeDefault
altAlternative text
fallbackFallback image URL to switch to on load failure; when not set, shows the "图片加载失败" placeholderstring
fitobject-fit valuestring
placeholderShow a light gray placeholder before the image finishes loadingboolean
previewEnable built-in preview: click to zoom + zoom/rotate/download + Esc to close + focus trapboolean
srcImage URLstring

Events

EventDescription
oas-previewPreview overlay opened, detail: { src }; closing the overlay does not emit an event