Image 图片

图片容器,在保留所有原生 img 的特性下,支持懒加载,自定义占位、加载失败等

基础用法

占位内容

加载失败

懒加载

图片预览

Image API

Image Attributes

Name说明类型Default
srcimage source, same as native.string
fitindicate how the image should be resized to fit its container, same as object-fit.'fill' | 'contain' | 'cover' | 'none' | 'scale'-down'
hide-on-click-modalwhen enabling preview, use this flag to control whether clicking on backdrop can exit preview mode.booleanfalse
lazywhether to use lazy load.booleanfalse
scroll-containerthe container to add scroll listener when using lazy load.string | HTMLElementthe nearest parent container whose overflow property is auto or scroll.
altnative attribute alt.string
referrer-policynative attribute referrerPolicy.string
preview-src-listallow big image preview.string[]
z-indexset image preview z-index.number
initial-indexinitial preview image index, less than the length of url-list.number0
preview-teleportedwhether to append image-viewer to body. A nested parent element attribute transform should have this attribute set to true.booleanfalse

Image Events

Name说明Type
loadsame as native load.(e: Event) => void
errorsame as native error.(e: Error) => void
switchtrigger when switching images.(index: number) => void
closetrigger when clicking on close button or when hide-on-click-modal enabled clicking on backdrop.() => void

Image Slots

插槽名说明
placeholdertriggers when image load.
errortriggers when image load failed.
viewerdescription of the image.

Image Viewer API

Image Viewer Attributes

Name说明类型Default
url-listpreview link list.string[][]
z-indexpreview backdrop z-index.number | string
initial-indexthe initial preview image index, less than or equal to the length of url-list.number0
infinitewhether preview is infinite.booleantrue
hide-on-click-modalwhether user can emit close event when clicking backdrop.booleanfalse
teleportedimage 自身是否插入至 body 元素上。 A nested parent element attribute transform should have this attribute set to true.booleanfalse

Image Viewer Events

事件名说明Type
closetrigger when clicking on close button or when hide-on-click-modal enabled clicking on backdrop.() => void
switchtrigger when switching images.(index: number) => void