这是效果
首先我们在vue项目中安装依赖
npm install v-viewer --save
接下来我们找到项目中的main.js
import 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' }
})
最后就是我们拿来使用了
<viewer :images="imgs"> <img v-for="src in imgs" :src="src.url" :key="src.title"> </viewer> data () { return { imgs: [ {url: 'https://img.yzcdn.cn/vant/apple-1.jpg', title: '图一'}, {url: 'https://img.yzcdn.cn/vant/apple-1.jpg', title: '图二'}, {url: 'https://img.yzcdn.cn/vant/apple-1.jpg', title: '图三'} ] } },