/*! For license information please see 3139.614ab879.js.LICENSE.txt */ (self.webpackChunk=self.webpackChunk||[]).push([["3139"],{68171:function(t,n,s){"use strict";s.r(n);var a=s("80681");let e=["innerHTML"];n.default={setup:()=>({html:""}),render:()=>((0,a.wg)(),(0,a.iD)("div",{class:"van-doc-markdown-body",innerHTML:'

Image

\n

Intro

\n

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

\n

Install

\n

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

\n
import { createApp } from 'vue';\nimport { Image as VanImage } from 'vant';\n\nconst app = createApp();\napp.use(VanImage);\n
\n

Usage

\n

Basic Usage

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

Fit Mode

\n

Same as object-fit.

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

Position

\n

Same as object-position.

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

Round

\n

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

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

Lazy Load

\n
<van-image\n  width="100"\n  height="100"\n  lazy-load\n  src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"\n/>\n
\n
import { createApp } from 'vue';\nimport { Lazyload } from 'vant';\n\nconst app = createApp();\napp.use(Lazyload);\n
\n

API

\n

Props

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
AttributeDescriptionTypeDefault
srcSrcstring-
fitFit mode, same as object-fitstringfill
positionPosition, 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-sizeIcon sizenumber | string32px
icon-prefixIcon className prefixstringvan-icon
crossoriginsame as crossoriginstring-
referrerpolicysame as referrerpolicystring-
\n

fit optional value

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
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
\n

Events

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
EventDescriptionArguments
clickEmitted when image is clickedevent: MouseEvent
loadEmitted when image loadedevent: Event
errorEmitted when image load failed-
\n

Slots

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

Types

\n

The component exports the following type definitions:

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

Theming

\n

CSS Variables

\n

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

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
NameDefault ValueDescription
--van-image-placeholder-text-colorvar(--van-text-color-2)-
--van-image-placeholder-font-sizevar(--van-font-size-md)-
--van-image-placeholder-backgroundvar(--van-background)-
--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)-
\n
'},null,8,e))}}}]);