# v-viewer **Repository Path**: crazy_about_programming/v-viewer ## Basic Information - **Project Name**: v-viewer - **Description**: 这是一个改良版的图片预览组件,调大了工具栏的尺寸, 增加了全屏,下载图片的功能,且在inline模式下,可以关闭预览窗口, 然后再次打开窗口 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-19 - **Last Updated**: 2025-05-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # v-viewer-picture Image viewer component for vue, supports rotation, scale, zoom and so on, based on [viewer.js](https://github.com/fengyuanchen/viewerjs) [![npm version](https://img.shields.io/npm/v/v-viewer.svg)](https://www.npmjs.com/package/v-viewer) [![language](https://img.shields.io/badge/language-Vue3-brightgreen.svg)](https://www.npmjs.com/package/v-viewer) [![npm version](https://img.shields.io/npm/v/v-viewer/legacy.svg)](https://www.npmjs.com/package/v-viewer) [![language](https://img.shields.io/badge/language-Vue2-brightgreen.svg)](https://www.npmjs.com/package/v-viewer) [![npm download](https://img.shields.io/npm/dw/v-viewer.svg)](https://www.npmjs.com/package/v-viewer) [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://mit-license.org/) ## [v-viewer for vue2](https://github.com/mirari/v-viewer/tree/v2) ## [Live demo](https://mirari.github.io/vue3-viewer/) ## Quick Example - [directive](https://codepen.io/mirari/pen/yLMPPWy) - [component](https://codepen.io/mirari/pen/ZEeaaWZ) - [api](https://codepen.io/mirari/pen/qBrVpNV) - [thumbnail & source](https://codepen.io/mirari/pen/Vwpryax) - [viewer callback](https://codepen.io/mirari/pen/eYveypz) - [custom toolbar](https://codepen.io/mirari/pen/ZEXqyPq) - [filter images](https://codepen.io/mirari/pen/mdWqpwa) - [change images](https://codepen.io/mirari/pen/ExWbovw) ## [中文文档](https://mirari.cc/posts/vue3-viewer) ## Installation Install from NPM ```bash npm install v-viewer-picture ``` ## Usage To use `v-viewer-picture`, simply import it and the `css` file, and call `app.use()` to install. The component, directive and api will be installed together in the global. Two different API styles are both supported: **Options API** and **Composition API**. ```ts import { createApp } from 'vue' import App from './App.vue' import 'viewerjs-vue/dist/viewer-vue.css' import VueViewer from 'v-viewer-picture' const app = createApp(App) app.use(VueViewer) app.mount('#app') ``` ```vue ``` ### 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. ```vue ``` #### Directive 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. ```vue
``` ##### 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. ```vue
``` ### Usage of component You can simply import the component and register it locally too. ```vue ``` #### Component props ##### images - Type: `Array` ##### trigger - Type: `Object` You can replace `images` with `trigger`, to accept any type of prop. when the `trigger` changes, the component will re-render the viewer. ```vue
``` ##### 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. ```vue ``` #### Component events ##### inited - viewer: `Viewer` Listen for the `inited` event to get the `viewer` instance, or use `this.refs.xxx.$viewer`. ### Usage of api > 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. ```vue ``` ## Options & Methods of Viewer 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: ```ts import { createApp } from 'vue' import 'viewerjs-vue/dist/viewer-vue.css' import VueViewer from 'v-viewer-picture' import App from './App.vue' export const app = createApp(App) app.use(VueViewer, { name: 'vuer', debug: true, }) app.mount('#app') ``` ```vue ``` ### defaultOptions - Type: `Object` - Default: `undefined` If you need to set the viewer default options, you can import it like this: ```ts import { createApp } from 'vue' import 'viewerjs-vue/dist/viewer-vue.css' import VueViewer from 'v-viewer-picture' import App from './App.vue' export const app = createApp(App) app.use(VueViewer, { defaultOptions: { zIndex: 9999 } }) app.mount('#app') ``` And you can reset the default options at any other time: ```javascript import VueViewer from 'v-viewer-picture' VueViewer.setDefaults({ zIndexInline: 2021, }) ```