# v-viewer **Repository Path**: knight.me/v-viewer ## Basic Information - **Project Name**: v-viewer - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2018-06-25 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # v-viewer Image viewer component for vue, supports rotation, scale, zoom and so on, based on [viewer.js](https://github.com/fengyuanchen/viewerjs) [![npm version](https://badge.fury.io/js/v-viewer.svg)](https://badge.fury.io/js/v-viewer) ## [Live demo](http://mirari.github.io/v-viewer/) ## Quick Example - [CodePen](https://codepen.io/mirari/pen/PePrVq) - [JSFiddle](https://jsfiddle.net/mirari/n1L0gxtv/) ## [中文文档](http://mirari.cc/2017/08/27/Vue%E5%9B%BE%E7%89%87%E6%B5%8F%E8%A7%88%E7%BB%84%E4%BB%B6v-viewer%EF%BC%8C%E6%94%AF%E6%8C%81%E6%97%8B%E8%BD%AC%E3%80%81%E7%BC%A9%E6%94%BE%E3%80%81%E7%BF%BB%E8%BD%AC%E7%AD%89%E6%93%8D%E4%BD%9C/) ## 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 ```bash npm install v-viewer ``` ## Usage To use `v-viewer`, simply import it and the `css` file, and call `Vue.use()` to install. ```html ``` ### Support UMD #### Browser ```html ... ``` #### CommonJS ```javascript var VueViewer = require('VueViewer') ``` #### AMD ```javascript require(['VueViewer'], function (VueViewer) {}); ``` ### 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. ```html ``` ### Usage of component You can simply import the component and register it locally too. Use [scoped slot](https://vuejs.org/v2/guide/components.html#Scoped-Slots) to customize the presentation of your images. Listen for the `inited` event to get the `viewer` instance, or use `this.refs.xxx.$viewer`. ```html ``` You can replace `images` with `trigger`, to accept any type of prop. when the `trigger` changes, the component will re-render the viewer. ```html
``` ## Options & Methods Refer to [viewer.js](https://github.com/fengyuanchen/viewerjs). ## Plugin options ### name - Type: `String` - Default: `viewer` If you need to avoid name conflict, you can import it like this: ```html ``` ### defaultOptions - Type: `Object` - Default: `undefined` If you need to set the viewer default options, you can import it like this: ```javascript import Viewer from 'v-viewer' import Vue from 'vue' Vue.use(Viewer, { defaultOptions: { zIndex: 9999 } }) ``` And you can reset the default options at any other time: ```javascript import Viewer from 'v-viewer' import Vue from 'vue' Vue.use(Viewer) Viewer.setDefaults({ zIndexInline: 2017 }) ```