我试着用下面的代码使用要求JS使用jquery,主干,下划线使用requirejs全局?
require.config({
waitSeconds: 0,
paths: {
underscore: 'underscore/underscore',
backbone: "backbone/backbone-min",
jquery: "jquery/jquery-min",
customhandler: "jquery/customhandler"
},
shim: {
underscore: {
deps: ['underscore'],
exports: '_'
}
}
});
创建单独的文件customhandler.js
和里面我想使用骨干,jQuery的,包括我的自定义JS文件,强调
define(['jquery','underscore','backbone'], function($,_,Backbone) {
//using jquery
var oldAjax = $.ajax;
$.ajax = function(options) {
console.log(options)
// Do your magic.
return oldAjax.apply($, arguments);
}
//need to use backbone,underscore here
});
但我仍然不能让它加载到我的应用程序。请告知。
我在下面的回答中指出你的'shim'为'jqueryajaxhandler' *是一个问题。它可能不是唯一的问题,但它仍是一个问题。这绝对是错误的。所以你应该删除它。另外,你的编辑还远离[mcve]。你现在的问题没有什么能够锻炼你的重写。 – Louis
@Louis现在更新我的问题。对困惑感到抱歉。 – mymotherland
@mymotherland其中是您的脚本从配置的入口点? – Nirus