【问题标题】:Photoswipe and Require.js configurationPhotoswipe 和 Require.js 配置
【发布时间】:2015-10-28 13:40:55
【问题描述】:

我有一个依赖于 PhotoSwipe 和 PhotoSwipeUI_Default 的模块。我需要两个模块,就像这样,在我的模块内部我正在初始化我的画廊。例如:

define("modules/lightboxStart", ["vendor/PhotoSwipe", "vendor/PhotoSwipeUI_Default"], function (PhotoSwipe, PhotoSwipeUI_Default) {

   var StartGallery = function(){
      var lightBox =  new PhotoSwipe($pswp, PhotoSwipeUI_Default, items, options);
            lightBox.init();
   }
   StartGallery()
}

然后库按预期工作但 require 在 PhotoSwipe.js 中引发不匹配的匿名定义模块错误。

查看文档后,我得出结论,我需要通过 require.js API 运行这两个脚本(PhotoSwipe 和 PhotoSwipeUI_Default)。

然后我定义了每个,像这样:

define('PhotoSwipe', function() {
//PhotoSwipe script here
 return PhotoSwipe
 })

define('PhotoSwipeUI_Default', function() {
//PhotoSwipeUI_Default script here
 return PhotoSwipeUI_Default
 })

这消除了我之前遇到的不匹配的匿名定义模块错误,但我现在收到了这个错误:

PhotoSwipe is not a function

我该如何解决这个问题?我本质上是在尝试访问 PhotoSwipe.js 中的 PhotoSwipe 函数并传递我的参数,但是如果在页面上产生大量 js 错误,我就无法这样做,而且我不知道为什么。

非常感谢您的帮助!

【问题讨论】:

  • 您需要对它们进行 SHIM,然后在其中使用依赖项
  • Shim 需要两个 PhotoSwipe 依赖项的脚本,然后将它们列为它们在 shim 中的依赖项?或者 Shim 供应商脚本?

标签: require photoswipe


【解决方案1】:

define( ["modules/lightboxStart", "vendor/PhotoSwipe", "vendor/PhotoSwipeUI_Default"], function (lightboxStart, PhotoSwipe, PhotoSwipeUI_Default) { //我是这么认为的}

【讨论】:

  • 虽然这在理论上可以回答这个问题,it would be preferable 在此处包含答案的基本部分,并提供链接以供参考。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-26
  • 2013-03-23
  • 2014-02-06
  • 2014-12-18
  • 2013-01-28
相关资源
最近更新 更多