简单讲下sea.js使用的代码结构

某htm模板

display("elements/header.phtml", array(·
'title' => 'title',
'keywords' => '',
'description' => '',
'nav' => 'nav',
'addStyle' => array('www/xxx/index.css'),

));

?>


...html code...


display("elements/footer.phtml", array(
    'modules' => array('www/xxx/index.js'),
));
?>

该html模版的footer模版



首先引入的公共js代码modules/www/common/common.js

define(function(require, exports, module) {
    //json工具函数
    require('../../public/json2');

    //获取并显示用户数据模块;
    require('./mod/user.loaded.data');

    //弹出登录模块;
    require('./mod/singinbox');

    //引入退出登录模块;
    require('./mod/logout');

    //头部菜单显示隐藏;
    require('./mod/menu');

    //返回顶部;
    require('./mod/gotop');
    
    //根据屏幕大小调整侧栏位置;
    require('./mod/adjustToolBar');
    
    //头部搜索框;
    require('./mod/search');


});

$modules php变量中单独引入的js代码

define(function(require, exports, module) {
  var a = require('./a')
  a.doSomething()
  var b = require('./b')
  b.doSomething()
})

附录:
关于require.js和sea.js的比较,这里阮老师的blog和玉伯(sea.js的作者)的知乎,挺不错的
http://www.ruanyifeng.com/blog/2012/10/asynchronous_module_definition.html
http://www.ruanyifeng.com/blog/2012/11/require_js.html
https://www.zhihu.com/question/20351507

你可能感兴趣的:(简单讲下sea.js使用的代码结构)