rap2hpoutre / vue-picture-swipe

🖼 Vue Picture Swipe Gallery (a gallery of image with thumbnails, lazy-load and swipe) backed by photoswipe
MIT License
396 stars 50 forks source link

Cant open/trigger lightbox via click or function #25

Open uchoasvinicius opened 4 years ago

uchoasvinicius commented 4 years ago

I searched the documentation and implementation itself, but found nothing similar to opening a gallery via @click or via a function called outside the component itself.

theprobugmaker commented 4 years ago

I think that this component is kinda encapsulated in the way it's created, I don't think it has customization support.

PizzaPete commented 4 years ago

A bit dirty, but I'm doing this following way:

import PhotoSwipe from 'photoswipe/dist/photoswipe';
import * as DefaultPhotoSwipeUI from 'photoswipe/dist/photoswipe-ui-default';
methods: {
    openGallery() {
      const pswpElement = document.querySelectorAll('.pswp')[0];
      const gallery = new PhotoSwipe(pswpElement, DefaultPhotoSwipeUI,
        this.images,
        {
          captionEl: false,
          shareEl: false,
        });
      gallery.init();
    },
}

Where this.images is the array containing the images passed down to PhotoSwipe.