Skip to content

ImagePreview 图片预览

介绍

一屏展示图片,可放大预览。

函数调用

为了便于使用 ImagePreview,提供了 showImagePreview函数,便于调用 ImagePreview,可设置标识指定一个 ImagePreview 组件调用。

WARNING

因小程序无法动态挂载组件,使用时需要页面存在一个 ImagePreview 组件,且函数调用方法需要在 onLoad 生命周期后调用。

html
<vd-image-preview name="page" />
ts
import { showImagePreview } from 'vital-design';

// 配置同组件 props
showImagePreview({
  name: 'page',
  images: [...],
  active: 2,
});

基础用法

通过 v-model 来设置是否展示,通过 images 属性来设置图片列表。

html
<vd-image-preview v-model="state.show" :images="state.images" />
ts
const state = reactive({
  show: false,
  images: [...],
});

激活位置

通过 active-index 属性来设置激活图片索引。

html
<vd-image-preview
  v-model="state.show"
  :active="state.active"
  :images="state.images"
/>
ts
const state = reactive({
  show: false,
  images: [...],
  active: 2,
});

展示关闭按钮

通过 closeable 属性来展示关闭按钮。

html
<vd-image-preview
  v-model="state.show"
  :images="state.images"
  closeable
/>
ts
const state = reactive({
  show: false,
  images: [...],
});

使用页码插槽

通过 index 插槽来自定义页码。

html
<vd-image-preview
  v-model="state.show"
  :images="state.images"
>
  <template #index="{ active, total }">
    第 {{ active + 1 }} 页
  </template>
</vd-image-preview>
ts
const state = reactive({
  show: false,
  images: [...],
});

使用视图插槽

通过 view 插槽来自定义视图内容,可使用图片、视频或其他自定义内容。

html
<vd-image-preview
  v-model="state.show"
  :images="state.images"
>
  <template #view="{ src, index }">
    <video :poster="src" style="width:100%;"></video>
  </template>
</vd-image-preview>
ts
const state = reactive({
  show: false,
  images: [...],
});

API

Props

参数说明类型默认值
name标识名称string-
show是否展示booleanfalse
images图片列表string[]-
active激活索引number0
zoomable是否允许缩放booleantrue
min-zoom最小缩放比例number | string0.3
max-zoom最大缩放比例number | string5
show-index是否显示页码booleantrue
closeable是否展示关闭按钮booleanfalse
close-icon关闭按钮图标IconsName'round-close-fill'
close-icon-size关闭按钮图标大小number | string24
close-on-click点击时关闭booleantrue
close-on-click-view点击视图时关闭,优先级高于 closeOnClickbooleantrue
show-menu-by-longpress开启长按图片显示识别小程序码菜单booleanfalse
z-index层级string | number2001+

代替原始 Props

参数说明类型默认值
custom-id根节点idstring-
custom-class根节点类名ClassValue-
custom-style根节点样式StyleValue-

Events

事件名说明回调参数
click点击时触发MouseEvent
click-close点击关闭按钮时触发MouseEvent
click-view点击视图时触发ImagePreviewOnClickViewEvent
open打开时触发-
opened打开动画结束时触发-
close关闭时触发-
closed关闭动画结束时触发-

Slots

名称说明
view预览视图
cover预览覆盖
index页码
close关闭按钮

Expose

方法名说明参数返回值
open打开预览ImagePreviewOpenOption-
close关闭预览--

赣ICP备2025061025号-1