【VUE】图片预览放大缩小插件

2019-06-04 17:44:14

参考地址 【VUE】图片预览放大缩小插件

第一种:viewerjs使用介绍

viewerjs插件截图

1、先安装依赖
npm install v-viewer --save

2、main.js内引用并注册调用

//main.jsimport Viewer from 'v-viewer'import 'viewerjs/dist/viewer.css'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" }
});

3、代码中使用xxx.vue

<template>
    <div class="content">
        <h1>Viewer图片预览插件</h1>
        <viewer :images="imgs">
            <img v-for="src in imgs" :src="src.url" :key="src.title">
        </viewer>
   </div></template><script>export default {
  data () {    return {      imgs: [
       {          url: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=85690711,3884201894&fm=27&gp=0.jpg',          title: '图片1'
        },
        {          url: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3564877025,796183547&fm=27&gp=0.jpg',          title: '图片2'
        }
      ]
    }
  },
}</script>

viewerjs使用配置参数


第二种:vue-photo-preview使用介绍

vue-photo-preview插件截图


1、先安装依赖
npm install vue-photo-preview --save

2、main.js内引用并注册调用

//main.jsimport preview from 'vue-photo-preview'import 'vue-photo-preview/dist/skin.css'Vue.use(preview)

3、代码中使用xxx.vue

<template>
    <div class="content">
       <section>
        <h1>preview图片预览插件</h1>
        <img v-for="src in imgs" :src="src.url" :key="src.title" :preview="src.preview" :preview-text="src.title">
    </section>
   </div></template><script>export default {
  data () {    return {      imgs: [
       {          url: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=85690711,3884201894&fm=27&gp=0.jpg',          title: '图片1',          preview: '1'
        },
        {          url: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3564877025,796183547&fm=27&gp=0.jpg',          title: '图片2',          preview: '1'
        }
      ]
    }
  },
}</script>

option配置请查看 http://photoswipe.com/documentation/options.html


第三种:vue-picture-preview使用介绍

vue-picture-preview插件截图


1、先安装依赖
npm install vue-picture-preview --save

2、main.js内引用并注册调用

//main.jsiimport vuePicturePreview from 'vue-picture-preview'Vue.use(vuePicturePreview)

3、在根组件添加 lg-preview 组件的位置

<!-- APP.vue --><div id="app">
    <router-view></router-view>
    <lg-preview></lg-preview></div>

4、代码中使用xxx.vue

<template>
    <div class="content">
        <h1>vuePicturePreview图片预览插件</h1>
        <img v-for="(img,index) in imgs"
        v-preview="img.url"
        :src="img.url"
        :alt="img.title"
        :key="index"
        preview-title-enable="true"
        preview-nav-enable="true">
   </div></template><script>export default {
  data () {    return {      imgs: [
       {          url: 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=85690711,3884201894&fm=27&gp=0.jpg',          title: '图片1'
        },
        {          url: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=3564877025,796183547&fm=27&gp=0.jpg',          title: '图片2'
        }
      ]
    }
  },
}</script>

总结

这三个插件介绍完了,除了第三种vue-picture-preview插件只有预览和切换上下张功能,另外两种都有放大和缩小(包括手势)以及其他功能。还是蛮好上手的插件,但我是更喜欢第一种




  • 2020-03-18 21:30:57

    基于OpenLayers实现地理围栏 谷歌百度高德地图都可以

    前言.因为项目有点特殊,需要接入谷歌地图实现地理围栏,因为谷歌地图的地理围栏接口相关接口并不完善,于是就换了一个思路,利用OpenLayers来实现地理围栏 openlayers 中文地址 http://weilin.me/ol3-primer/ch02/index.html 作者:zcty0701 链接:https://www.jianshu.com/p/60e88ee1e843 来源:简书 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

  • 2020-03-19 17:12:40

    百度地图放大覆盖物消失

    产生问题的原因是因为我们用的普通的点数组生成的多边形,我们应该用百度的点数组生成就没问题了。

  • 2020-03-19 19:15:47

    vue中methods watch和compute的区别和联系

    首先要说,methods,watch和computed都是以函数为基础的,但各自却都不同 而从作用机制和性质上看,methods和watch/computed不太一样,所以我接下来的介绍主要有两个对比: 1.methods和(watch/computed)的对比

  • 2020-03-19 19:50:31

    用vue做的跟随鼠标移动的div

    随鼠标移动的动画效果,之前一直使用angular和react,没怎么接触过vue,先做一个vue的简单例子,然后再整合。

  • 2020-03-20 13:35:55

    随便想到,群聊天的数据库简单设计

    拆分成两个表,一个是消息的流水表,一个是每个人的配置表。 记录每个群下面的这个用户的最后读取的消息last_msg_id,然后在计算消息未读数据。 这样优化之后数据将减少好多,数量是 m+n条数据。不在是成倍增长了。

  • 2020-03-20 13:39:50

    类似与微信朋友圈功能数据库如何实现

    每次发圈子的时候,给关注我的每个uuid,发一个内容id。 大概表的设计就是 uuid,idlist 这样的,idlist是按照时间顺序的。 然后定期删除idlist过多的老圈子。