1. 什么是sea.js
Seajs是一个模块加载器 遵循 CMD 规范模块化开发,依赖的自动加载、配置的简洁清晰。 兼容性
Chrome 3+ Firefox 2+ Safari 3.2+ Opera 10+ IE 5.5+
2. 如何使用
去官网下载最新的seajs文件http://seajs.org/docs/#downloads 在页面引入seajs:
<script src="/site/script/sea.js"></script>
配置入口文件
<script type="text/javascript">seajs.use('./entry.js');</script>
用define函数定义模块
'use strict';
define(function (require, exports, module) {var router = require('./routes');var app = new Vue({el: '#app',router: router});
});
路由配置
'use strict';define(function (require, exports, module) {var router = new VueRouter({routes: [{path: '/route',component: function component(resolve, reject) {require.async(['../js/js路径'], function (res) {resolve(res);});}},
组件使用
'use strict';// 定义组件
define(function (require, exports, module) {// 行权var index= require('../template/index.html');var component1= require('./component1');module.exports = {// 引入模板template:index,data: function () {},components: {component1: component1}}
}