Preview Updated 2026-05-10

ImagePreview

Full-screen image viewer with wheel zoom, mouse drag, and keyboard +/− / 0 / Esc controls.

Basic usage

Typically triggered from a thumbnail: set the thumbnail to cursor: zoom-in and toggle open to true on click.

  • Mouse wheel: zoom
  • Mouse drag: pan
  • Keyboard + / -: zoom
  • Keyboard 0: reset to 100%
  • Keyboard Esc: close
背景
缩略图
<script setup lang="ts">
import { ref } from 'vue';
import { CfImagePreview, CfButton } from '@chufix-design/vue';

const open = ref(false);
const src = 'https://images.unsplash.com/photo-1503023345310-bd7c1de61c7d?w=1600&h=900&fit=crop';
</script>

<template>
  <div style="display: flex; flex-direction: column; gap: 12px; align-items: flex-start;">
    <img
      :src="src.replace('1600&h=900', '320&h=180')"
      alt="缩略图"
      style="width: 200px; height: auto; border-radius: 8px; cursor: zoom-in;"
      @click="open = true"
    />
    <CfButton size="sm" @click="open = true">点击预览大图</CfButton>
    <CfImagePreview v-model="open" :src="src" alt="示例图" />
  </div>
</template>
<img src={thumbSrc} onClick={() => setOpen(true)} style={{ cursor: 'zoom-in' }} />
<CfImagePreview open={open} onOpenChange={setOpen} src={fullSrc} alt="Example" />

API

PropTypeDefaultDescription
srcstringFull image URL
altstring''Alt text
open / modelValuebooleanControlled visibility
defaultOpenbooleanfalseUncontrolled initial visibility

Events: onOpenChange(open) / onClose().

反馈与讨论

ImagePreview · Discussion

0
0 / 600
一键发送
正在加载评论...