vue图片查看(放大、缩小、旋转)

v-viewer介绍

基于viewer.js用于图片浏览的Vue组件,支持旋转、缩放、翻转等操作。官方文档地址

示例:

<template>
  <div>
    <img v-for="{src, id} in images" :key="id" :src="src" @click="show(id)">
  </div>
</template>
<script>
  import 'viewerjs/dist/viewer.css'
  import VueViewer from 'v-viewer'
  import Vue from 'vue'
  Vue.use(VueViewer)
  export default {
    data() {
      return {
        images: [
          {
          "src": "https://picsum.photos/200/200",
          "data-source": "https://picsum.photos/200/200",
          "id": "1"
        },
          {
          "src": "https://picsum.photos/200/200",
          "data-source": "https://picsum.photos/200/200",
          "id": "2"
        }
        ]
      };
    },
    methods: {
      show(id) {
        const index = this.images.indexOf(id)
        this.$viewerApi({
          images: this.images,
          options: {
            toolbar: true,
            url: 'data-source',
            initialViewIndex: index
          }
        })
      },
    },
  }
</script>

posted @ 2022-03-05 00:48  我爱这世间美貌女子  阅读(1328)  评论(0编辑  收藏  举报