Vue 使用 Viewers 实现图片的 放大缩小、 旋转 、 拖拉等操作、支持多图片

目录

方式一 element ui自己搞了一个 这种

方式二 使用插件


方式一 element ui自己搞了一个 这种

方式二 使用插件

先看效果图吧,这是单张图片的。放大缩小支持鼠标滚轴操作。

具体的操作

首先Vue需要安装插件

npm install v-viewer --save      或者       cnpm install v-viewer --save    

(最好使用cnpm 淘宝镜像,npm不可以的话就试试cnpm)

安装成功的话 ,你的package.json 文件里面会 有"v-viewer": "^1.2.1",

然后是使用

这里就是全部代码了

<template>
    <section>
       <div>                                  
           <el-row style="text-align: center;" >
                <viewer :images="signImages" style="z-index:0;">
                    <img :src="img" :key="src" width="500">
                </viewer>
           </el-row>
           <el-row style="text-align: center;">
                <el-button>打印</el-button>
           </el-row>
        </div>
    </section>
</template>
<script>
	import Vue from 'vue';
	import Viewer from 'v-viewer'
	import 'viewerjs/dist/viewer.css'

export default {
    data() {
	return {
                img:""
            }
        },
        methods: {

        },
        mounted() {
            //这里指明图片
            this.img = localStorage.getItem("img")
            Vue.use(Viewer);
            Viewer.setDefaults({
            Options: { "inline": true, "button": true, "navbar": true, "title": true, "toolbar": true, "tooltip": true, "movable": true, "zoomable": true, "rotatable": true, "scalable": true, "transition": true, "fullscreen": true, "keyboard": true, "url": "data-source" }
            });
}
}
</script>
<style scoped>

</style>

 想要实现多张图片

的这种左右选择的方式,就将图片循环放到<viewer></viewer>插件里

<viewer :images="signImages" style="z-index:0;">
   <img  v-for="img in images" :src="img" :key="src" width="500">
</viewer>

大体就是这么个方式了。

下面是他的一些默认配置

名称类型默认值说明
inline布尔值false启用 inline 模式
button布尔值true显示右上角关闭按钮(jQuery 版本无效)
navbar布尔值/整型true显示缩略图导航
title布尔值/整型true显示当前图片的标题(现实 alt 属性及图片尺寸)
toolbar布尔值/整型true显示工具栏
tooltip布尔值true显示缩放百分比
movable布尔值true图片是否可移动
zoomable布尔值true图片是否可缩放
rotatable布尔值true图片是否可旋转
scalable布尔值true图片是否可翻转
transition布尔值true使用 CSS3 过度
fullscreen布尔值true播放时是否全屏
keyboard布尔值true是否支持键盘
interval整型5000播放间隔,单位为毫秒
zoomRatio浮点型0.1鼠标滚动时的缩放比例
minZoomRatio浮点型0.01最小缩放比例
maxZoomRatio数字100最大缩放比例
zIndex数字2015设置图片查看器 modal 模式时的 z-index
zIndexInline数字0设置图片查看器 inline 模式时的 z-index
url字符串/函数src设置大图片的 url
build函数null回调函数,具体查看演示
built函数null回调函数,具体查看演示
show函数null回调函数,具体查看演示
shown函数null回调函数,具体查看演示
hide函数null回调函数,具体查看演示
hidden函数null回调函数,具体查看演示
view函数null回调函数,具体查看演示
viewed函数null回调函数,具体查看演示

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值