/*! 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:'
Enhanced img tag with multiple image fill modes, support for image lazy loading, loading hint, loading failure hint.
\nRegister component globally via app.use
, refer to Component Registration for more registration ways.
import { createApp } from 'vue';\nimport { Image as VanImage } from 'vant';\n\nconst app = createApp();\napp.use(VanImage);\n
\n<van-image\n width="100"\n height="100"\n src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"\n/>\n
\nSame 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
\nSame 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
\nShow round image, it may not works at fit=contain
and fit=scale-down
.
<van-image\n round\n width="10rem"\n height="10rem"\n src="https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg"\n/>\n
\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
\nimport { createApp } from 'vue';\nimport { Lazyload } from 'vant';\n\nconst app = createApp();\napp.use(Lazyload);\n
\nAttribute | \nDescription | \nType | \nDefault | \n
---|---|---|---|
src | \nSrc | \nstring | \n- | \n
fit | \nFit mode, same as object-fit | \nstring | \nfill | \n
position | \nPosition, same as object-position, can be set to top right bottom left or string | \nstring | \ncenter | \n
alt | \nAlt | \nstring | \n- | \n
width | \nWidth | \nnumber | string | \n- | \n
height | \nHeight | \nnumber | string | \n- | \n
radius | \nBorder Radius | \nnumber | string | \n0 | \n
round | \nWhether to be round | \nboolean | \nfalse | \n
block 3.6.3 | \nWhether the root node is a block element | \nboolean | \nfalse | \n
lazy-load | \nWhether to enable lazy load, should register Lazyload component | \nboolean | \nfalse | \n
show-error | \nWhether to show error placeholder | \nboolean | \ntrue | \n
show-loading | \nWhether to show loading placeholder | \nboolean | \ntrue | \n
error-icon | \nError icon | \nstring | \nphoto-fail | \n
loading-icon | \nLoading icon | \nstring | \nphoto | \n
icon-size | \nIcon size | \nnumber | string | \n32px | \n
icon-prefix | \nIcon className prefix | \nstring | \nvan-icon | \n
crossorigin | \nsame as crossorigin | \nstring | \n- | \n
referrerpolicy | \nsame as referrerpolicy | \nstring | \n- | \n
name | \ndescription | \n
---|---|
contain | \nKeep aspect ratio, fully display the long side of the image | \n
cover | \nKeep aspect ratio, fully display the short side of the image, cutting the long side | \n
fill | \nStretch and resize image to fill the content box | \n
none | \nNot resize image | \n
scale-down | \nTake the smaller of none or contain | \n
Event | \nDescription | \nArguments | \n
---|---|---|
click | \nEmitted when image is clicked | \nevent: MouseEvent | \n
load | \nEmitted when image loaded | \nevent: Event | \n
error | \nEmitted when image load failed | \n- | \n
Name | \nDescription | \n
---|---|
default | \nCustom the content below the image | \n
loading | \nCustom loading placeholder | \n
error | \nCustom error placeholder | \n
The component exports the following type definitions:
\nimport type { ImageFit, ImagePosition, ImageProps } from 'vant';\n
\nThe component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.
\nName | \nDefault Value | \nDescription | \n
---|---|---|
--van-image-placeholder-text-color | \nvar(--van-text-color-2) | \n- | \n
--van-image-placeholder-font-size | \nvar(--van-font-size-md) | \n- | \n
--van-image-placeholder-background | \nvar(--van-background) | \n- | \n
--van-image-loading-icon-size | \n32px | \n- | \n
--van-image-loading-icon-color | \nvar(--van-gray-4) | \n- | \n
--van-image-error-icon-size | \n32px | \n- | \n
--van-image-error-icon-color | \nvar(--van-gray-4) | \n- | \n