安装
npm install v-viewer@next
全局注册 main.js文件中
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
const app = createApp(App)
app.use(Viewer, {
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",
}
})
使用
<div v-viewer>
<img v-for="src in images" :key="src" :src="src"/>
</div>
<viewer :images="images">
<img v-for="src in images" :key="src" :src="src">
</viewer>
<a v-if="images?.length" @click="showImagesInViewer(images)">查看</a>
const showImagesInViewer = (urls)=> {
urls instanceof Array &&
urls?.length &&
this.$viewerApi({ images: urls })
},
- 示例
- 我用的是第三种,直接通过事件触发,不需要图片出现后再去点击图片触发预览
- 更多使用方法和配置项可参考v-viewer中文文档