我有 jQuery
和通过 RequireJS
加载的 jQuery
插件。
这就是我的 requirejs.config
的样子:
requirejs.config({
baseUrl: "http://mysite.example.com",
"paths": {
// libraries
"jquery": "Static/js/library/jquery/jquery-1.10.2",
"jquery_sortable" : "Static/js/library/jquery-sortable/jquery-sortable",
shim: {
'jquery_sortable': ['jquery']
}
}
});
当我快速刷新页面两次或更多次时,有时
我会在插件代码中遇到异常:
Uncaught ReferenceError :jQuery 未定义
。
基本上,我的插件不使用我为其设置的shim
。
指定我的 shim
配置的最可靠方法是什么??
最佳答案
可能是因为您没有按预期构建。正如您所注意到的,您将 shim
放入 paths
中。可能是。
"paths": {
// libraries
"jquery": "Static/js/library/jquery/jquery-1.10.2",
"jquery_sortable" : "Static/js/library/jquery-sortable/jquery-sortable",
shim: {
'jquery_sortable': ['jquery']
}
}
--------评论后编辑------
也许尝试定义手册中声明的 dep?
'foo': {
deps: ['bar'],
...
关于javascript - 如何使用 requirejs 正确定义 shim 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20099763/