ruby-on-rails 如何使用Rails和Importmap导入PhotoSwipe

wyyhbhjk  于 2023-04-22  发布在  Ruby
关注(0)|答案(1)|浏览(167)

我已经固定了photoswipe:

./bin/importmap pin photoswipe --download

在app/javascript/application.js中添加了

import PhotoSwipeLightbox from 'photoswipe'
document.addEventListener("turbo:load", function() {
  const lightbox = new PhotoSwipeLightbox({
    gallery: '#existing-files',
    children: '.gal',
    pswpModule: () => import('photoswipe')
  });
  lightbox.init();
});

lightbox在页面加载时立即打开,但图像丢失。pswpModule:()=〉import('photoswipe')似乎不起作用,但没有给出错误。

lnlaulya

lnlaulya1#

我想出来了。我需要:

./bin/importmap pin photoswipe --download
./bin/importmap pin photoswipe/lightbox --download

然后

import PhotoSwipeLightbox from 'photoswipe/lightbox'

相关问题