首页>Magento>source

app/code/{vendor}/{module}/view/frontend/requirejs-config.js

var config = {
    map: {
        '*': {
            'Magento_Swatches/js/swatch-renderer' : 'Wac_SwatchName/js/swatch-renderer',
            'magento-swatch.renderer' : 'Magento_Swatches/js/swatch-renderer',
            'CustomName' : 'Vendor_Module/view/frontend/web/js/custom',
        }
    }
};

app/code/Vendor/Module/view/frontend/web/js/custom.js

$(document).on('swatch.initialized', function() {
 alert('test');
}

仅我的自定义Js文件工作当我的自定义模块加载时,但现在自定义js没有正确加载,请检查我的自定义js文件和requirejs-config文件

最新回答
  • 2019-12-5
    1 #

    调用正确的模块名称和文件名 requirejs-config.js

     "CustomName": "Vendor_Module/js/custom"
    

    需要在custom.js中声明require方法

    require([
        "jquery"
    ], function($) {
    $(document).on('swatch.initialized', function() {
    alert('test');
    });
    });
    

相关问题

  • magento2:如何使用magento 2中的对象管理器从前端删除产品?
  • magento2.3.1:如何以编程方式在magento 23中对特定父类别的子类别进行排序