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