RequireJS - 用法

来源:互联网 发布:金山打字通mac版官网 编辑:程序博客网 时间:2024/06/16 09:30
首页在html页面中写入:  
[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <script src="js/require.js" data-main="js/main"></script>  
data-main属性的作用是,指定网页程序的主模块。在上例中,就是js目录下面的main.js,这个文件会第一个被require.js加载。由于require.js默认的文件后缀名是js,所以可以把main.js简写成main。

[javascript] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. /* 
  2. * main.js 
  3. */  
  4.   
  5. (function() {  
  6.      require.config({  
  7.           baseUrl : './',  
  8.           paths : {  
  9.                jquery : 'assets/js/jquery/jquery.min',  
  10.                bootstrap : 'assets/bootstrap/js/bootstrap.min'  
  11.           },  
  12.           shim : {  
  13.                bootstrap : {  
  14.                     deps : [ 'jquery' ],  
  15.                     exports : 'bootstrap'  
  16.                }  
  17.           }  
  18.            
  19.      });  
  20.      require(['bootstrap' ], function() {  
  21.           console.log(all loaded);  
  22.      });  
  23. })(this);  
baseUrl :基目录;
paths :js文件路径;
shim : 配置依赖关系;
require([主模块])
0 0
原创粉丝点击