Mixin 没生效时最浪费时间的做法,是不断在 JS 文件里加 console.log。如果 RequireJS 根本没合并到那份配置,日志写再多也不会出现。
先在控制台确认目标模块有没有注册mixin
打开页面后执行:
require.s.contexts._.config.config.mixins找到目标模块,例如:
Magento_Checkout/js/action/place-order如果这里没有你的 mixin,问题在 requirejs-config.js 的位置、作用域或模块名,而不是 mixin 函数本身。前台文件应放在:
app/code/Vendor/Module/view/frontend/requirejs-config.js后台则是 view/adminhtml,全局才用 view/base。
模块名要写AMD名称,不要写磁盘路径
var config = {
config: {
mixins: {
'Magento_Checkout/js/action/place-order': {
'Vendor_Module/js/action/place-order-mixin': true
}
}
}
};Mixin 文件返回的函数还要包住原目标:
define([], function () {
'use strict';
return function (target) {
return target.extend({
// override here
});
};
});如果目标导出的是普通函数而不是 UI Component,就要返回一个包装函数,不能机械地 target.extend()。
生产模式下重新部署对应 area、theme 和 locale 的静态资源,然后清浏览器缓存。最后不仅要看到 mixin 文件 200,还要在 mixins 配置中看到它,并确认目标方法确实走进覆盖逻辑。

