1.配置:myconfig.js(按需配置)
require.config({
baseUrl: "../style/js",
//该路径下的文件
paths: {
'jquery': 'jQuery-1.11.0',
}
});
2.html文档中加载如下文件
<script type="text/javascript" src="../style/js/require.js"></script>
<script type="text/javascript" src="../style/js/myconfig.js"></script>
底部配置:
<script language='javascript'>
//该页面需要加载的js页面
require(['../js/example'], function (modal) {
modal.init();
});
</script>
3.js配置
define(['jquery'],function ($) {
var modal = {}
modal.init = function(){
console.log(1);
}
return modal;
});
完成