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 can achieve various functions such as image zoom, shrink, rotate, drag, and preview. The effect is great. I discovered this repository on Github while browsing, and I found it very useful, so I want to share the usage process.

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

1. Installation#

npm install v-viewer

2. Usage#

Create a new file 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 is a small component page or a root page, depending on where you want to introduce this functionality. Just include the parameters class, v-viewer, v-highlight.

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