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>