Gathering detailed insights and metrics for v-viewer-image
Gathering detailed insights and metrics for v-viewer-image
Gathering detailed insights and metrics for v-viewer-image
Gathering detailed insights and metrics for v-viewer-image
v-viewer
Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
@jimengio/image-viewer
[](https://www.npmjs.com/package/@jimengio/image-viewer)
v-img-viewer
Vuejs plugin for image viewing
fzb-v-viewer
Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
npm install v-viewer-image
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
1
25
Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
.css
file:import 'viewerjs-advance/dist/viewer.css'
Install from NPM
1npm install v-viewer-image
To use v-viewer
, simply import it and the css
file, and call Vue.use()
to install.
1<template> 2 <div> 3 <!-- directive --> 4 <div class="images" v-viewer-image> 5 <img v-for="src in images" :key="src" :src="src"> 6 </div> 7 <!-- component --> 8 <viewer :images="images"> 9 <img v-for="src in images" :key="src" :src="src"> 10 </viewer> 11 <!-- api --> 12 <button type="button" @click="show">Click to show</button> 13 </div> 14</template> 15<script> 16 import 'viewerjs-advance/dist/viewer.css' 17 import VueViewer from 'v-viewer-image' 18 import Vue from 'vue' 19 Vue.use(VueViewer) 20 export default { 21 data() { 22 return { 23 images: [ 24 "https://picsum.photos/200/200", 25 "https://picsum.photos/300/200", 26 "https://picsum.photos/250/200" 27 ] 28 }; 29 }, 30 methods: { 31 show() { 32 this.$viewerImageApi({ 33 images: this.images, 34 }) 35 }, 36 }, 37 } 38</script>
1<link href="//unpkg.com/viewerjs-advance/dist/viewer.css" rel="stylesheet"> 2<script src="//unpkg.com/vue/dist/vue.js"></script> 3<script src="//unpkg.com/viewerjs-advanc/dist/viewer.js"></script> 4<script src="//unpkg.com/v-viewer/dist/v-viewer.js"></script> 5<script> 6 Vue.use(VueViewer.default) 7</script>
1var VueViewer = require('VueViewer')
1require(['VueViewer'], function (VueViewer) {});
Just add the directive v-viewer
to any element, then all img
elements in it will be handled by viewer
.
You can set the options like this: v-viewer="{inline: true}"
Get the element by selector and then use el.$viewer
to get the viewer
instance if you need.
1<template> 2 <div> 3 <div class="images" v-viewer="{movable: false}"> 4 <img v-for="src in images" :src="src" :key="src"> 5 </div> 6 <button type="button" @click="show">Show</button> 7 </div> 8</template> 9<script> 10 import 'viewerjs/dist/viewer.css' 11 import { directive as viewer } from "v-viewer" 12 export default { 13 directives: { 14 viewer: viewer({ 15 debug: true, 16 }), 17 }, 18 data() { 19 return { 20 images: [ 21 "https://picsum.photos/200/200", 22 "https://picsum.photos/300/200", 23 "https://picsum.photos/250/200" 24 ] 25 }; 26 }, 27 methods: { 28 show () { 29 const viewer = this.$el.querySelector('.images').$viewer 30 viewer.show() 31 } 32 } 33 } 34</script>
The viewer
instance will be created only once after the directive binded.
If you're sure the images inside this element won't change again, use it to avoid unnecessary re-render.
1<div class="images" v-viewer.static="{inline: true}"> 2 <img v-for="src in images" :src="src" :key="src"> 3</div>
The viewer
instance will be updated by update
method when the source images changed (added, removed or sorted) by default.
If you encounter any display problems, try rebuilding instead of updating.
1<div class="images" v-viewer.rebuild="{inline: true}"> 2 <img v-for="src in images" :src="src" :key="src"> 3</div>
You can simply import the component and register it locally too.
Use scoped slot to customize the presentation of your images.
1<template> 2 <div> 3 <viewer :options="options" :images="images" 4 @inited="inited" 5 class="viewer" ref="viewer" 6 > 7 <template #default="scope"> 8 <img v-for="src in scope.images" :src="src" :key="src"> 9 {{scope.options}} 10 </template> 11 </viewer> 12 <button type="button" @click="show">Show</button> 13 </div> 14</template> 15<script> 16 import 'viewerjs-advance/dist/viewer.css' 17 import { component as Viewer } from "v-viewer-image" 18 export default { 19 components: { 20 Viewer 21 }, 22 data() { 23 return { 24 images: [ 25 "https://picsum.photos/200/200", 26 "https://picsum.photos/300/200", 27 "https://picsum.photos/250/200" 28 ] 29 }; 30 }, 31 methods: { 32 inited (viewer) { 33 this.$viewer = viewer 34 }, 35 show () { 36 this.$viewer.show() 37 } 38 } 39 } 40</script>
Array
Object
You can replace images
with trigger
, to accept any type of prop.
when the trigger
changes, the component will re-render the viewer.
1<viewer :trigger="externallyGeneratedHtmlWithImages"> 2 <div v-html="externallyGeneratedHtmlWithImages"/> 3</viewer>
Boolean
false
The viewer instance will be updated by update
method when the source images changed (added, removed or sorted) by default.
If you encounter any display problems, try rebuilding instead of updating.
1<viewer 2 ref="viewer" 3 :options="options" 4 :images="images" 5 rebuild 6 class="viewer" 7 @inited="inited" 8> 9 <template #default="scope"> 10 <img v-for="src in scope.images" :src="src" :key="src"> 11 {{scope.options}} 12 </template> 13</viewer>
Viewer
Listen for the inited
event to get the viewer
instance, or use this.refs.xxx.$viewer
.
Only available in modal mode.
You can call the function: this.$viewerApi({options: {}, images: []})
to show gallery without rendering the img
elements yourself.
The function returns the current viewer instance.
1<template> 2 <div> 3 <button type="button" class="button" @click="previewURL">URL Array</button> 4 <button type="button" class="button" @click="previewImgObject">Img-Object Array</button> 5 </div> 6</template> 7<script> 8 import 'viewerjs-advance/dist/viewer.css' 9 import { api as viewerApi } from "v-viewer-image" 10 export default { 11 data() { 12 sourceImageURLs: [ 13 'https://picsum.photos/200/200?random=1', 14 'https://picsum.photos/200/200?random=2', 15 ], 16 sourceImageObjects: [ 17 { 18 'src':'https://picsum.photos/200/200?random=3', 19 'data-source':'https://picsum.photos/800/800?random=3' 20 }, 21 { 22 'src':'https://picsum.photos/200/200?random=4', 23 'data-source':'https://picsum.photos/800/800?random=4' 24 } 25 ] 26 }, 27 methods: { 28 previewURL () { 29 // If you use the `app.use` full installation, you can use `this.$viewerApi` directly like this 30 const $viewer = this.$viewerApi({ 31 images: this.sourceImageURLs 32 }) 33 }, 34 previewImgObject () { 35 // Or you can just import the api method and call it. 36 const $viewer = viewerApi({ 37 options: { 38 toolbar: true, 39 url: 'data-source', 40 initialViewIndex: 1 41 }, 42 images: this.sourceImageObjects 43 }) 44 } 45 } 46 } 47</script>
Refer to viewer.js.
String
viewer
If you need to avoid name conflict, you can import it like this:
1<template> 2 <div> 3 <!-- directive name --> 4 <div class="images" v-vuer="{movable: false}"> 5 <img v-for="src in images" :src="src" :key="src"> 6 </div> 7 <button type="button" @click="show">Show</button> 8 <!-- component name --> 9 <viewer :images="images"> 10 <img v-for="src in images" :src="src" :key="src"> 11 </viewer> 12 </div> 13</template> 14<script> 15 import 'viewerjs-advance/dist/viewer.css' 16 import Viewer from 'v-viewer-image' 17 import Vue from 'vue' 18 Vue.use(Viewer, {name: 'viewer'}) 19 export default { 20 data() { 21 return { 22 images: [ 23 "https://picsum.photos/200/200", 24 "https://picsum.photos/300/200", 25 "https://picsum.photos/250/200" 26 ] 27 }; 28 }, 29 methods: { 30 show () { 31 // viewerjs instance name 32 const vuer = this.$el.querySelector('.images').$vuer 33 vuer.show() 34 // api name 35 this.$vuerApi({ 36 images: this.images 37 }) 38 } 39 } 40 } 41</script>
Object
undefined
If you need to set the viewer default options, you can import it like this:
1import VueViewer from 'v-viewer-image' 2import Vue from 'vue' 3Vue.use(VueViewer, { 4 defaultOptions: { 5 zIndex: 9999 6 } 7})
And you can reset the default options at any other time:
1import VueViewer from 'v-viewer-image' 2import Vue from 'vue' 3Vue.use(VueViewer) 4VueViewer.setDefaults({ 5 zIndexInline: 2017 6})
No vulnerabilities found.
No security vulnerabilities found.