Image Preview
点一张图,在浮层里看大图。可以带一组缩略图。打开时锁住页面滚动,点遮罩或按 Escape 关掉。基于 Reka UI Primitive,动画用 motion-v。
顺便一提,open 只向外发 update:open,组件不读这个 prop。
Installation
pnpm dlx @weme-ui/weme-ui add image-previewUsage

Vueexamples/usage.vueExpand codeHide code
<script lang="ts" setup>
import ImagePreview from '../image-preview.vue'
const previews = [
{ src: 'https://github.com/antfu.png', alt: 'Antfu' },
{ src: 'https://github.com/yyx990803.png', alt: 'Yyx990803' },
{ src: 'https://github.com/posva.png', alt: 'Posva' },
]
</script>
<template>
<ImagePreview
:previews="previews"
src="https://github.com/moujinet.png"
width="100"
class="rounded-xl"
/>
</template>Examples
Disabled

Vueexamples/disabled.vueExpand codeHide code
<script lang="ts" setup>
import ImagePreview from '../image-preview.vue'
</script>
<template>
<ImagePreview disabled src="https://github.com/moujinet.png" width="100" class="rounded-xl" />
</template>Props
PropTypeDefault
asAsTag | Component'img'
触发图渲染成的元素或组件,传给内部
Image。根节点固定是 divAsTag | Component'img'
asChildboolean-
已声明,模板没有使用
boolean-fit'none' | 'contain' | 'cover' | 'fill' | 'scale''contain'
传给触发图和预览图
'none' | 'contain' | 'cover' | 'fill' | 'scale''contain'
srcstring-
触发图地址。没有缩略图时,预览也用它
string-widthstring | number-
触发图宽度
string | number-
heightstring | number-
触发图高度
string | number-
fallbackSrcstring-
传给触发图、预览图和缩略图
string-fallbackDelayMsnumber0
传给触发图和预览图
number0altstring-
传给触发图和预览图。缩略图用各自的
altstring-loading'eager' | 'lazy'-
传给触发图和预览图
'eager' | 'lazy'-
referrerPolicy'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'-
传给触发图和预览图
'' | 'no-referrer' | 'no-referrer-when-downgrade' | 'origin' | 'origin-when-cross-origin' | 'same-origin' | 'strict-origin' | 'strict-origin-when-cross-origin' | 'unsafe-url'-
crossOrigin'' | 'anonymous' | 'use-credentials'-
传给触发图和预览图
'' | 'anonymous' | 'use-credentials'-
openboolean-
已声明。内部自己记开关,不读取这个值
boolean-previewsImagePreviewItem[]-
缩略图。单项含
src、可选 altImagePreviewItem[]-
loadingTextstring'Loading...'
预览图还没
loaded 时的文案string'Loading...'loadingIconIconifyIconProps['icon']'ri:loader-line'
加载图标(Iconify)
IconifyIconProps['icon']'ri:loader-line'
closeOnEscapebooleantrue
为
true 时监听 Escape 关闭。只在创建时读取一次booleantruedisabledboolean-
为
true 时点击不会开关,浮层也不传送到 bodyboolean-classany-
根节点额外 class
any-uiPartial<ImagePreviewStyleSlots>-
覆盖 slots 样式(
root / trigger / content / viewport / loading / loadingText / loadingIcon / preview / previewImage / thumbs / thumb / thumbImage / overlay)Partial<ImagePreviewStyleSlots>-
Events
EventType
update:openvalue: boolean
开关变化时触发
value: boolean
Slots
SlotDescription
default替换触发图。未提供时用 src 渲染一张 Image
替换触发图。未提供时用
src 渲染一张 ImageAccessibility
根节点是 div,data-slot="image-preview",data-state 为 open 或 closed。浮层有 aria-label="Image Preview"。打开时锁住 body 滚动。点遮罩关闭。缩略图是 li,当前项带 data-highlighted。alt 会传给 Image,但 Image 目前没有写到元素上。
Keyboard Interactions
KeyDescription
Escape关闭预览。closeOnEscape 为 false 时不监听
关闭预览。
closeOnEscape 为 false 时不监听Files
src/components/image-preview/image-preview.vuesrc/components/image-preview/image-preview.props.tssrc/components/image-preview/image-preview.style.ts