英文:
How to import PhotoSwipe with Rails and Importmap
问题
在 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')
似乎不起作用,但也没有报错。
英文:
I've pinned photoswipe:
./bin/importmap pin photoswipe --download
in app/javascript/application.js I've added
import PhotoSwipeLightbox from 'photoswipe'
document.addEventListener("turbo:load", function() {
const lightbox = new PhotoSwipeLightbox({
gallery: '#existing-files',
children: '.gal',
pswpModule: () => import('photoswipe')
});
lightbox.init();
});
The lightbox opens straight away on page load but the image is missing. pswpModule: () => import('photoswipe') doesn't appear to work but no error is given.
答案1
得分: 1
我已解决。我需要:
./bin/importmap pin photoswipe --download
./bin/importmap pin photoswipe/lightbox --download
然后
import PhotoSwipeLightbox from 'photoswipe/lightbox'
英文:
I worked it out. I needed:
./bin/importmap pin photoswipe --download
./bin/importmap pin photoswipe/lightbox --download
then
import PhotoSwipeLightbox from 'photoswipe/lightbox'
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论