Vue.js Image Viewer With v-viewer / Viewer.js

Dec 2, 2019

Why use v-viewer / Viewer.js

  • Zoom capability
  • Gallery/Navbar (show thumbnail of gallery images at bottom)

Installation / Setup

Install package

npm install v-viewer

Edit main.js

import 'viewerjs/dist/viewer.css'import Viewer from 'v-viewer'Vue.use(Viewer)

Usage

<template>  <div v-viewer="viewerOptions">    <img v-for="image in images" :src="image.src" :key="image.src" :data-href="image.href" :alt="image.alt">  </div></template><script>export default {  data() {    return {      viewerOptions: {        movable: false,        rotatable: false,        scalable: false,        url: 'data-href',        title(image, imageData) {          // if want to show blank title, must use alt=" "          return image.alt        },      },      images: [        { src: 'https://picsum.photos/id/1/150/150', href: 'https://picsum.photos/id/1/800/800', alt: ' ' },        { src: 'https://picsum.photos/id/2/150/150', href: 'https://picsum.photos/id/2/800/800', alt: ' ' },        { src: 'https://picsum.photos/id/3/150/150', href: 'https://picsum.photos/id/3/800/800', alt: ' ' },        { src: 'https://picsum.photos/id/4/150/150', href: 'https://picsum.photos/id/4/800/800', alt: ' ' },        { src: 'https://picsum.photos/id/5/150/150', href: 'https://picsum.photos/id/5/800/800', alt: ' ' },        { src: 'https://picsum.photos/id/6/150/150', href: 'https://picsum.photos/id/6/800/800', alt: ' ' }      ]    }  }}</script>

References:

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.