安装
npm install v-viewer
引入
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
Vue.use (Viewer, {defaultOptions: {'navbar': true,'toolbar': false,'movable': false,'title': false,'zoomable': true,'scalable': true,'transition': true}
})
使用
方法一:组件
<viewer :images="imgList" class="imgClass"><div v-for="(item,index) in imgList" :key="index"><img :src="item"/></div>
</viewer>
方法二:API
<template><div><button type="button" class="button" @click="preview">preview</button></div>
</template>
<script>export default {data() {imgList: ['https://chserver.oss-cn-hangzhou.aliyuncs.com/articles/542fb7ca81f29d177ac1c5918cd4d5ee.png','https://chserver.oss-cn-hangzhou.aliyuncs.com/photos/ca9cd2d535fb610f4ca141cb9bf95d9d.jpg']},methods: {preview () {this.$viewerApi({options: {initialViewIndex: 1},images: this.imgList})}}}
</script>
效果
