v-viewer
Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
Live demo
Examples
- directive
- component
- thumbnail & source
- viewer callback
- hide img tags
- filter images
- change images
- click buttons to show different images
中文文档
Migration from 0.x
- The only change you have to make is to manually import the
.css
file:
import 'viewerjs/dist/viewer.css'
Installation
Install from GitHub via NPM
npm install v-viewer
Usage
To use v-viewer
, simply import it and the css
file, and call Vue.use()
to install.
<!-- directive --> ... <!-- component -->
Support UMD
Browser
...
CommonJS
var VueViewer =
AMD
;
Usage of directive
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.
Show
Direcitve modifiers
static
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.
<div class="images" v-viewer.static="{inline: true}">
<img v-for="src in images" :src="src" :key="src">
</div>
rebuild
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.
<div class="images" v-viewer.rebuild="{inline: true}">
<img v-for="src in images" :src="src" :key="src">
</div>
Usage of component
You can simply import the component and register it locally too.
Use scoped slot to customize the presentation of your images.
{{scope.options}} Show
Component props
images
- Type:
Array
trigger
- Type:
Array
You can replace images
with trigger
, to accept any type of prop.
when the trigger
changes, the component will re-render the viewer.
rebuild
- Type:
Boolean
- Default:
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.
{{scope.options}}
Component events
inited
- viewer:
Viewer
Listen for the inited
event to get the viewer
instance, or use this.refs.xxx.$viewer
.
Options & Methods of Viewer
Refer to viewer.js.
Plugin options
name
- Type:
String
- Default:
viewer
If you need to avoid name conflict, you can import it like this:
Show
defaultOptions
- Type:
Object
- Default:
undefined
If you need to set the viewer default options, you can import it like this:
Vue
And you can reset the default options at any other time:
VueViewer