requirejs + jquery 插件触发类型错误:对象 [对象对象] 没有方法插件



通常是一个简单的问题

为什么它总是有效:

require.config({
    shim: {
        'jquery': {exports: 'jQuery'},
        'jquery.plugin': { exports: 'jQuery', deps: ['jquery'] },
    },
});
define([
    'jquery.plugin'
], function($) {
    $('body').plugin();
});

因此,工作并不总是:

require.config({
    shim: {
        'jquery': {exports: 'jQuery'},
        'jquery.plugin': { deps: ['jquery'] },
    },
});
define([
    'jquery', 'jquery.plugin'
], function($) {
    $('body').plugin();
});

周期性触发错误-"TypeError:Object[Object Object]没有方法"plugin"。

例如,我意识到当方法定义键时,"export"配置参数的确定。当你写:

define([
    'jquery', 'jquery.plugin'
], function(dep1, dep2) {
    ..
});

dep1并不总是==dep2(但有时O_O)。

这里可能有什么问题?

简单回答:

通过requirejs-config中的jQuery,YII Assets(AppAsset::register($this))并行加载另一个url jQuery的另一个副本。。。

最新更新