【问题标题】:Use jQuery with RequireJS separately单独使用 jQuery 和 RequireJS
【发布时间】:2013-01-21 10:58:47
【问题描述】:

我正在尝试加载和使用 jQuery,我不想使用 RequireJs+jQuery 捆绑包,因为我不打算使用最新版本。 但是,它似乎没有执行文档就绪事件,

require.config({
    baseUrl: 'js/'
});


require([
    "jquery.min",
    "jquery.alpha",
    "jquery.beta"
], function($) {

    console.log('require js okay');

    define(['jquery'], function ($) {

        $(document).ready(function() {

            console.log('jquery has loaded');
            $('body').alpha().beta();

        });

    });

});

【问题讨论】:

    标签: javascript jquery include requirejs require


    【解决方案1】:

    jQuery exports itself as a named module。这意味着您需要在配置选项中添加一个路径才能正确地将 jQuery 作为模块返回。

      paths: {
        "jquery": "js/jquery,
      },
    

    【讨论】:

    • 调用jquery.min 仍然不会返回您的jQuery 对象。路径 必须 字面意思是 jquery 以返回 jQuery。
    • 我还是不太明白这是怎么工作的。如果 jQuery 将自己导出为命名模块,为什么我必须首先对其进行配置?它不应该自动将 jquery 检测为模块吗?我通过 CDN 加载了 jQuery,我不完全确定您如何配置路径。我应该将 jquery cdn 链接放在路径中吗?
    猜你喜欢
    • 1970-01-01
    • 2012-06-07
    • 2016-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多