import{o as s,a,y as e}from"./vue-libs.b44bc779.js";const d={class:"van-doc-markdown-body"},n=e(`

Image

Intro

Enhanced img tag with multiple image fill modes, support for image lazy loading, loading hint, loading failure hint.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { Image as VanImage } from 'vant';

const app = createApp();
app.use(VanImage);

Usage

Basic Usage

<van-image
  width="100"
  height="100"
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>

Fit Mode

Same as object-fit.

<van-image
  width="10rem"
  height="10rem"
  fit="contain"
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>

Position

Same as object-position.

<van-image
  width="10rem"
  height="10rem"
  fit="cover"
  position="left"
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>

Round

Show round image, it may not works at fit=contain and fit=scale-down.

<van-image
  round
  width="10rem"
  height="10rem"
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>

Lazy Load

<van-image
  width="100"
  height="100"
  lazy-load
  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"
/>
import { createApp } from 'vue';
import { Lazyload } from 'vant';

const app = createApp();
app.use(Lazyload);

API

Props

AttributeDescriptionTypeDefault
srcSrcstring-
fitFit mode, same as object-fitstringfill
position v3.4.2Position, same as object-position, can be set to top right bottom left or stringstringcenter
altAltstring-
widthWidthnumber | string-
heightHeightnumber | string-
radiusBorder Radiusnumber | string0
roundWhether to be roundbooleanfalse
block 3.6.3Whether the root node is a block elementbooleanfalse
lazy-loadWhether to enable lazy load, should register Lazyload componentbooleanfalse
show-errorWhether to show error placeholderbooleantrue
show-loadingWhether to show loading placeholderbooleantrue
error-iconError iconstringphoto-fail
loading-iconLoading iconstringphoto
icon-size v3.0.11Icon sizenumber | string32px
icon-prefixIcon className prefixstringvan-icon

fit optional value

namedescription
containKeep aspect ratio, fully display the long side of the image
coverKeep aspect ratio, fully display the short side of the image, cutting the long side
fillStretch and resize image to fill the content box
noneNot resize image
scale-downTake the smaller of none or contain

Events

EventDescriptionArguments
clickEmitted when image is clickedevent: MouseEvent
loadEmitted when image loaded-
errorEmitted when image load failed-

Slots

NameDescription
defaultCustom the content below the image
loadingCustom loading placeholder
errorCustom error placeholder

Types

The component exports the following type definitions:

import type { ImageFit, ImagePosition, ImageProps } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-image-placeholder-text-colorvar(--van-text-color-2)-
--van-image-placeholder-font-sizevar(--van-font-size-md)-
--van-image-placeholder-background-colorvar(--van-background-color)-
--van-image-loading-icon-size32px-
--van-image-loading-icon-colorvar(--van-gray-4)-
--van-image-error-icon-size32px-
--van-image-error-icon-colorvar(--van-gray-4)-
`,17),o=[n],h={__name:"README",setup(l,{expose:t}){return t({frontmatter:{}}),(c,i)=>(s(),a("div",d,o))}};export{h as default};