我在RequiredJS中有一个简单的示例,并尝试加载jQuery文件,但抛出错误。我在做什么错了?
层次结构
index.html
scripts/
libs/
jquery.js
compute/
config.js
requirejs.config({
baseUrl: 'scripts/libs'
});
requirejs(['jquery'],
function(sub) {
console.log(sub);
});
SCRIPT5022:“ jquery”的脚本错误 http://requirejs.org/docs/errors.html#scripterror require.js(7,175)
答案 0 :(得分:1)
以下类似内容适用于我:
requirejs.config({
// Path mappings for the logical module names
paths: (function () {
var pathObj = {};
pathObj = {
'jquery': '../your/path/to/js/libs/jquery/jquery-3.1.1.min'
};
return pathObj;
})(),
// Shim configurations for modules that do not expose AMD
shim: {
'jquery': {
exports: ['jQuery', '$']
}
}
});
require(['jquery'],
function ($) {
$.ajax({/*some ajax call for example */});
}
);