requirejs.config({ urlArgs: "ver=1.0_" + (new Date).getTime(), baseUrl: '/static/js/', paths: { //第三方库的路径配置 jquery: 'lib/jquery/jquery-1.9.1.min', //jquery bootstrap: 'lib/bootstrap/js/bootstrap.min', //bootstrap jqueryCookie: 'lib/jquery-cookie/jquery.cookie', //cookie插件 template: 'lib/template/template', //模板引擎 templaten: 'lib/template/template-native', //模板引擎-后端写法 jqueryLazyload: 'lib/jQuery-plugins/jquery.lazyload.min', //图片延迟加载 dialog: 'lib/dialog/dialog', //artDialog弹窗插件 dialogConf: 'lib/dialog/dialog-config', drag: 'lib/dialog/drag', popup: 'lib/dialog/popup', swiper: 'lib/swiper/swiper.min', //焦点图插件 nprogress: 'lib/nprogress/nprogress', //页面加载loading组件 //自己写的路径配置 Tools: 'common/tools', addressApi: 'api/index' //所有Ajax存放地 }, shim: { bootstrap: { deps: ['jquery'] }, jqueryLazyload: { deps: ['jquery'] }, dialog: { deps: ['jquery', 'dialogConf', 'drag', 'popup'], exports: 'dialog' }, swiper: { deps: ['jquery'], exports: 'swiper' }, nprogress: { deps: ['jquery'], exports: 'nprogress' } } }); //所有页面都需要的js,先行加载 require(['jquery', 'nprogress', 'addressApi']); require(["jquery"], function ($) { //ajax加载页面跳转 $(document).ajaxStart(function () { $('.loading').show(); }).ajaxStop(function () { $('.loading').hide(); }); //根据条件加载不同js文件 var currentPage = $("#require-page").attr("current-page"); var targetModule = $("#require-page").attr("target-module"); if (targetModule) { // 页面加载完毕后再执行相关业务代码比较稳妥 $(function () { require([targetModule], function (targetModule) { // 不要在这里写业务代码 //全部统一调用init方法 //也就是每个模块都暴露一个init方法用于事件监听,页面内容加载等 targetModule.init(currentPage); }); }); return; } })