未捕获的ReferenceError:未定义jQuery-Magento 2.3

时间:2019-02-03 13:51:29

标签: jquery magento fancybox-3

我正在尝试让fancybox在Magento 2.3(带有Infortis Ultimo主题)中工作。

但是我得到了:

1. Uncaught ReferenceError: jQuery is not defined 
2. Uncaught TypeError: fancyboxExample.init is not a function

我正在尝试使用以下解决方案:

https://magento.stackexchange.com/questions/158894/jquery-fancybox-for-magento-2

错误

enter image description here

我使用default_head_blocks.xml通过<link src="js/custom.js"/>加载了以下内容。

require(['jquery', 'fancybox', 'domReady!'], function($, fancybox, doc) {
var fancyboxExample = {
    openModal: function() {
        $.fancybox.open(this.$modal);
    },
    closeModal: function() {
        $.fancybox.close(true);
    }
};
fancyboxExample.init();
});

谁能对此有所了解? 谢谢,

1 个答案:

答案 0 :(得分:1)

您的必需JS配置应为

File: app/design/frontend/Store/theme/requirejs-config.js

  var config = {
    map: {
      '*': {
        fancybox: 'js/vendor/fancybox3/jquery.fancybox.min'
         }
     },
    shim: {
            'fancybox': {
                deps: ['jquery']
            }
        }
 };