zishu's blog

zishu's blog

一个热爱生活的博主。https://zishu.me

Implementing image zoom preview functionality in Nuxt.

v-viewer is a plugin based on Vue that allows for various functionalities such as image zooming, scaling, rotating, dragging, and previewing. The effects are great. I discovered this repository on Github while browsing and found it very useful, so I wanted to share the usage process.

Github: https://github.com/mirari/v-viewer

1. Installation#

npm install v-viewer

2. Usage#

Create a new file called viewer.js in the plugins directory.

// /plugins/viewer.js

import Vue from 'vue';
import Viewer from 'v-viewer'
import 'viewerjs/dist/viewer.css'
Vue.use(Viewer)
Viewer.setDefaults({
  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' }
})

Then, import it in nuxt.config.js.

// nuxt.config.js

plugins: [
	// ...
	{ src: '@/plugins/viewer', ssr: false }
],

Finally, import it in the page where you want to use it.

<div class="markdown-body-box" v-viewer v-highlight>
<!-- Page content -->
</div>

You can import it in any page, whether it's a small component page or the root page, depending on where you want to use this functionality. Just include the class, v-viewer, and v-highlight parameters.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.