【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-01-08 22:03:07

    修改MAC系统下默认PHP版本

    今天在使用mac时遇到了一个问题,因为需要composer拉取laravel5.6,但是提示我php版本过低,但是我本人使用的是集成环境MAMP,已经切换了php7.2的版本,这个为什么没有生效呢?经检查是因为composer检测得是mac下环境变量生效的php版本

  • 2020-01-08 23:37:08

    laravel通过图片流返回图片

    我用laravel的字母头像生成框架Laravolt\Avatar生成的base64头像,但我想做个通用但,直接返回图片,我还是根据以往但经验 改写header但返回值为图片返回值,结果返回失败,一堆乱吗,不知道为啥。 后来用了laravel自带但返回图片但方法,结果ok。记录下

  • 2020-01-08 23:45:06

    laravel response 对象一些常用功能点

    通常,我们并不只是从路由动作简单返回字符串和数组,大多数情况下,都会返回一个完整的 Illuminate\Http\Response 实例或 视图。

  • 2020-01-08 23:49:13

    laravel 存储base64格式图片

    一、总结 一句话总结: 二、laravel存储64位图片实例 三、laravel 存储前端上传base64图片 四、php将base64字符串转换为图片

  • 2020-01-09 01:24:28

    mac安装ImageMagick与PHP扩展Imagick

    mac安装ImageMagick和php7.2扩展Imagick,从网上搜索教程,感觉好少,有的教程看起来也很麻烦,不过安装起来,没想到竟然如此简单。不非纯灰之力。

  • 2020-01-09 18:49:17

    pecl安装卸载模块,如何自动配置php.ini

    利用pecl安装php模块,可能需要手工配置php.ini,以加载或禁止相关模块。那么pecl install是不是可以自动配置php.ini呢?答案是肯定的。在pecl isntall的提示信息中,苏南大叔找到了下面的类似提示信息:configuration option "php_ini" is not set to php.ini location。这个设置点,就是本文的关键所在。设置好"php_ini"之后,pecl就可以自动修改php.ini中的extension=了。