Magento 2 - 混合使用混合

5
如何为已存在的 mixin 构建一个mixin? 这是否可能?
我需要在 Vendor_Module:js/checkout-mixin 中覆盖一个函数,它已经是 Magento_Checkout:js/somethingmixin
我尝试在 requirejs-config.js 中设置它,就像我通常为定义mixin所做的那样,但它没有起作用。
直接为 Magento_Checkout:js/something 设置新的mixin 不可行。
谢谢。

我也尝试了同样的事情,但我也失败了。我认为将一个mixin混合到另一个mixin中是不可能的。 - Black
1个回答

0

抱歉,如果您想要在已经混入的文件中再次混入,这是可能的。

这里是Magento自己提供的面包屑JS的最佳示例

只需将此代码放入您的requirejs-config.js中即可

var config = {
    config: {
        mixins: {
            'Magento_Catalog/js/product/breadcrumbs': {
                'Vendor_ModuleName/js/breadcrumbs-mixin': true
            }
        }
    }
};

将此代码放入您自己的vendor_company模块中的js目录中

define([
    'jquery',
    'Magento_Catalog/js/product/breadcrumbs',
    'jquery/ui'
], function ($) {
    'use strict';
    return function (widget) {
        $.widget('mage.breadcrumbs', widget, {
            /**
             * {@inheritdoc}
             */
            _getCategoryCrumb: function (menuItem) {
                //do some custom stuff
                return this._super(menuItem);
            },
        });
        return $.mage.breadcrumbs;
    };
});

你可以像这样放置你的其他方法

_getCategoryCrumb: function (menuItem) {
                //do some custom stuff
                return this._super(menuItem);
            },

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接