1 Star 0 Fork 2

isee / vue3-preview

forked from 陈钦伟 / vue3-preview 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

vue3-preview

介绍

Vue3+TS的图片预览Vue组件,支持图片放大缩小、移动、快捷键操作等等。

下载

npm install vue3-preview -S

在线体验

橙某人 - 在线壁纸

使用说明

<template>
  <div>
    <div class="images">
      <img @click="imgHandle(url)" v-for="url in imagesData" :key="url" :src="url">
    </div>
    <button @click="clickHandle">点击预览图片</button>
    <preview :urlList="imagesData" v-model="visible"></preview>
    <preview ref="preview"></preview>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import Preview from 'vue3-preview';
export default defineComponent({
  name: 'App',
  components: {
    Preview
  },
  setup() {
    const preview = ref();
    const imagesData = ref([
      'http://p8.qhimg.com/bdm/1024_768_85/t01d0a11d2e93f10849.jpg',
      'http://p0.qhimg.com/bdm/1024_768_85/t0185100fadc5a11456.jpg',
      'https://blog-pro-vite.oss-cn-shanghai.aliyuncs.com/uploads/one/713591c5-153e-4675-ad82-961a1bec4692.png',
    ]);
    // 方式一
    const visible = ref(false)
    function clickHandle() {
      visible.value = true;
    }
    // 方式二
    function imgHandle(url: string) {
      preview.value?.open(url);
    }
    return {
      preview,
      imagesData,
      visible,
      clickHandle,
      imgHandle
    };
  }
})
</script>

<style scoped>
.images{
  display: flex;
}
.images img {
  width: 300px;
  height: fit-content;
  margin: 10px;
  cursor: pointer;
}
</style>

参数说明

参数 说明 类型 默认值
model-value / v-model 是否显示组件 boolean false
urlList 用于预览的图片链接列表,open方法的imgUrls参数会优先 string[] []
zIndex 预览时遮罩层的 z-index number 2000
hideOnClickModal 是否可以通过点击遮罩层关闭预览 boolean false
initialIndex 预览的首张图片的位置, 小于等于数组长度 Number 0
infinite 是否可以无限循环预览 boolean true
appendToBody 是否将组件插入至 body 元素上 boolean false

方法说明

事件名称 说明 回调参数
close 关闭组件触发
switch 当图片切换时触发 (val: number),切换目标的下标

具有功能

  • 上一张
  • 下一张
  • 放大
  • 缩小
  • 图片模式:fullscreen / original
  • 左旋转
  • 右旋转
  • 快捷键
    • 鼠标拖动
    • 鼠标滚轴放大缩小
    • esc键关闭
    • left键上一张
    • right键下一张
    • up键放大
    • down键缩小
    • down键缩小
    • space键切换图片模式
MIT License Copyright (c) 2021 橙某人 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

一个Vue3+TS的图片预览Vue组件,方便使用,拆箱即用,支持图片放大缩小、移动,键盘按键便捷操作等等。 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/lbj/vue3-preview.git
git@gitee.com:lbj/vue3-preview.git
lbj
vue3-preview
vue3-preview
master

搜索帮助