mirari / v-viewer

Image viewer component for vue, supports rotation, scale, zoom and so on, based on viewer.js
https://mirari.cc/v-viewer/
MIT License
2.49k stars 294 forks source link

open single image on click #268

Closed robertnicjoo closed 1 year ago

robertnicjoo commented 1 year ago

How can I open and image on click (no array of images, just single image)

mirari commented 1 year ago

Use api mode, and pass an array with one image: https://codepen.io/mirari/pen/NWpwVdd

robertnicjoo commented 1 year ago

Use api mode, and pass an array with one image: https://codepen.io/mirari/pen/NWpwVdd

TypeError: e.map is not a function


<img @click="show(post.media_url)" class="card-img-top" :src="post.media_url" height="150" :alt="post.alt">

show(url) {
  this.$viewerApi({
    images: url,
    options: {
      initialViewIndex: 2,
    },
  });
},

PS: my images are dynamic therefore I cannot have then on data{} (pre-loaded) like your sample code i must get them on page content instead.

mirari commented 1 year ago
this.$viewerApi({
    images: [url],
    options: {
      navbar: false,
    },
  });
robertnicjoo commented 1 year ago

Thank you, any suggestion on how to remove extra buttons such as play button?

mirari commented 1 year ago

Try this:

this.$viewerApi({
    images: [url],
    options: {
      navbar: false,
      toolbar: {
            zoomIn: true,
            zoomOut: true,
            oneToOne: true,
            reset: true,
            prev: false,
            play: false,
            next: false,
            rotateLeft: true,
            rotateRight: true,
            flipHorizontal: true,
            flipVertical: true,
          },
    },
  })        

https://github.com/fengyuanchen/viewerjs#toolbar

robertnicjoo commented 1 year ago

Amazing, Thanks a lot.