//单模块模式 seajs.use('./a'); //回调模式 seajs.use('./a',function(a) { a.dosomething(); }); //多模块模式 seajs.use(['./a','./b'],function(a, b) { a.dosomething(); b.dosomething(); });
下面可以看其官方给的simple例子中的页面怎么写的,基本上就明白了sea.js 是怎么用的了:
<script src="https://www.jb51.net/sea-modules/seajs/seajs/2.2.0/sea.js"></script> <script> // Set configuration seajs.config({ base: "../sea-modules/", alias: { "jquery": "jquery/jquery/1.10.1/jquery.js" } }); // For development if (location.href.indexOf("?dev") > 0) { seajs.use("../static/hello/src/main"); } // For production else { seajs.use("examples/hello/1.0.0/main"); } </script>
//mian.js
//hello/mian.js define(function(require) { var Spinning = require('./spinning'); var s = new Spinning('#container'); s.render(); });