首先,引入sea.js:(注意要直接写在Script标签里,不要写在jquery的页面加载事件里)

seajs.config({
base: "./" //seajs的基础路径(组织人事,元数据项目的模块)
,
charset: 'utf-8',
map: [
[/^(.*\.(?:css|js|html))(.*)$/i, '$1?v=_VERSION_' + '-' + '1.0']
] //加上版本号,清缓存用
//公共路径
,
paths: { }
}); seajs.use(["app.js"]);

然后在调用其它js的时候这样写:

define(function(require, exports, module) {
var sTpl = require("views/company.html"); var VueComponent = Vue.extend({
template: sTpl,
data: function() {
return {
class1: "modal fade in",
index: 1,
rows: 8,
next: false,
path: gMain.basePath,
logo: '' };
},
ready: function() {
this.getInfo()
},
methods: {
getInfo: function() {
var $url = gMain.basePath + 'api/company';
var resource = this.$resource($url)
resource.get({
pIndex: this.index,
pRows: this.rows
})
.then(function(response) {
var obj = eval('(' + response.data + ')');
if(obj.length == 0) {
this.show = true
this.next = false
this.$set('Complist', obj)
} else {
this.$set('Complist', obj)
if(this.index + 1 > obj[0].counts) {
this.next = false
} else
this.next = true
}
})
},
commit: function() {
var title = this.title;
var formData = new FormData($("#file")[0]);
var result;
$.ajax({
type: 'post',
dataType: "json",
async: false,
contentType: false,
processData: false,
url: gMain.basePath + "api/Company/PostFile",
data: formData,
success: function(data) {
result = data;
}
})
if(title == "新增") {
this.logo = result;
this.item.logo = this.logo;
var $url = gMain.basePath + 'api/Company/PostCompany';
var resource = this.$resource($url)
resource.save(this.item)
.then(function() {
this.getInfo();
this.$set('show', false);
})
}
if(title == "编辑") {
var b = document.getElementById("ed").src;
if(b.length > 100) {
this.logo = result;
this.item.logo = this.logo;
} else {}
var $url = gMain.basePath + 'api/Company/PutCompany';
var resource = this.$resource($url)
resource.update({
pId: this.item.company_id
}, this.item)
.then(function() {
this.getInfo();
this.$set('show', false);
})
}
},
start: function(company) {
var $url = gMain.basePath + 'api/company/PutCompanyStatus';
var resource = this.$resource($url)
resource.update({
pId: '2'
}, company)
.then(function() {
this.getInfo()
})
},
pause: function(company) {
var $url = gMain.basePath + 'api/company/PutCompanyStatus';
var resource = this.$resource($url)
resource.update({
pId: '1'
}, company)
.then(function() {
this.getInfo()
})
},
loadItem: function(company) {
this.$set('title', '编辑');
this.$set('item', company) },
addItem: function() {
this.$set('title', '新增');
this.$set('item', {})
},
cancle: function() {
this.$set('show', false);
this.$set('class1', 'modal fade');
},
nextpages: function() {
this.index = this.index + 1
this.getInfo()
},
addPic: function(e) {
e.preventDefault();
$('input[type=file]').trigger('click');
return false;
},
previewFile: function() {
var preview = document.querySelector('a.pict img');
var rewrew = document.querySelector('input[type=file]').files[0];
var reader = new FileReader();
reader.addEventListener("load", function() {
preview.src = reader.result;
}, false);
if(rewrew) {
reader.readAsDataURL(rewrew);
}
}
} }); module.exports = VueComponent;
});

然后注意如果要引入html文件琢模板,需要介入sea-text.js文件。

附App.js的写法:

/**
* Created by zackey on 2016/5/28.
*/
define(function (require,exports,module) {
require("components/menu.js"); //导航
require("components/loading.js"); //导航 // 路由器需要一个根组件。
var App = Vue.extend({}); // 创建一个路由器实例
var router = new VueRouter(); // 定义路由规则
router.map({
'/': {
component: function (resolve) {
require.async(['modules/Index.js'],resolve);
}
},
'/can': {
component: function (resolve) {
require.async(['modules/can.js'],resolve);
}
},
'/task': {
component: function (resolve) {
require.async(['modules/task.js'],resolve);
}
},
'/bar':{
component:function(resolve){
require.async(['modules/bar.js'],resolve);
}
},
'/foo':{
component:function(resolve){
require.async(['modules/foo.js'],resolve);
}
},
'/tool':{
component:function(resolve){
require.async(['modules/tool.js'],resolve)
}
},
'/datas':{
component:function(resolve){
require.async(['modules/datas.js'],resolve)
}
},
'/users':{
component:function(resolve){
require.async(['modules/users.js'],resolve)
}
},
'/roles':{
component:function(resolve){
require.async(['modules/roles.js'],resolve)
}
},
'/task_list':{
component:function(resolve){
require.async(['modules/task_list.js'],resolve)
}
},
'/task_save':{
component:function(resolve){
require.async(['modules/task_save.js'],resolve)
}
},
'/partner_list':{
component:function(resolve){
require.async(['modules/partner_list.js'],resolve)
}
},
'/wx_menu':{
component:function(resolve){
require.async(['modules/wx_menu.js'],resolve)
}
},
'/company':{
component:function(resolve){
require.async(['modules/company.js'],resolve)
}
}
});
//启动路由
// 路由器会创建一个 App 实例,并且挂载到选择符 #app 匹配的元素上。
router.start(App, '#app'); });

关于sea.js的笔记的更多相关文章

  1. js模块加载框架 sea.js学习笔记

    seajs实现了JavaScript 的 模块开发及按模块加载.用来解决繁琐的js命名冲突,文件依赖等问题,其主要目的是令JavaScript开发模块化并可以轻松愉悦进行加载. 官方文档:http:/ ...

  2. sea.js模块化编程

    * 为什么要模块化? 解决文件依赖 解决命名冲突 ; var var2 = 2; function fn1(){ } function fn2(){ } return { fn1: fn1, fn2: ...

  3. sea.js模块加载工具

    seajs的使用 seajs是一个jS模块加载器,由淘宝前端架构师玉伯开发,它可以解决命名空间污染,文件依赖的问题.可以在一个js文件中引入另外一个js.require('a.js') 1.安装 np ...

  4. js学习笔记:webpack基础入门(一)

    之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...

  5. Vue.js学习笔记(2)vue-router

    vue中vue-router的使用:

  6. 解决sea.js引用jQuery提示$ is not a function的问题

    在使用sea.js的如下写法引用jQuery文件时, //main.jsdefine(function(require,exports,module){ var $ = require('jquery ...

  7. js读书笔记

    js读书笔记 基本类型的基本函数总结 1. Boolean() 数据类型 转换为true的值 转换为false的值 Boolean true false String 任何非空字符串 "&q ...

  8. React.js入门笔记

    # React.js入门笔记 核心提示 这是本人学习react.js的第一篇入门笔记,估计也会是该系列涵盖内容最多的笔记,主要内容来自英文官方文档的快速上手部分和阮一峰博客教程.当然,还有我自己尝试的 ...

  9. 模块化开发--sea.js

    当你的网站开发越来越复杂的时候,会经常遇到一下问题吗?1.冲突2.性能3.依赖如果在多人开发或者是复杂的开发过程中会经常遇到这些问 题,就可以用模块化开发来解决.以上问题是如何产生的?1.冲突:如果你 ...

随机推荐

  1. JavaWeb -- Struts 数据传输:OGNL和类型转换

    1. 数据传输:OGNL和类型转换 OGNL和struts2 OGNL:Object-Graph Navigation Language. OGNL是集成进struts框架中比较强大的技术有助于数据传 ...

  2. Python基础笔记系列一:基本工具与表达式

    本系列教程供个人学习笔记使用,如果您要浏览可能需要其它编程语言基础(如C语言),why?因为我写得烂啊,只有我自己看得懂!! 工具基础(Windows系统下)传送门:Python基础笔记系列四:工具的 ...

  3. Word Search, 在矩阵中寻找字符串,回溯算法

    问题描述: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed ...

  4. Text Justification,文本对齐

    问题描述:把一个集合的单词按照每行L个字符放,每行要两端对齐,如果空格不能均匀分布在所有间隔中,那么左边的空格要多于右边的空格,最后一行靠左对齐. words: ["This", ...

  5. python测试函数的使用时间

    1. 使用装饰器来衡量函数执行时间 有一个简单方法,那就是定义一个装饰器来测量函数的执行时间,并输出结果:(代码通用3.x) import time from functools import wra ...

  6. asp.net获取URL和IP地址

    (转自:http://www.cnblogs.com/JuneZhang/archive/2010/11/26/1888863.html) HttpContext.Current.Request.Ur ...

  7. Flask 的路由系统 FBV 与 CBV

    Flask的路由系统 本质: 带参数的装饰器 传递函数后 执行 add_url_rule 方法 将 函数 和 url 封装到一个 Rule对象 将Rule对象 添加到 app.url_map(Map对 ...

  8. Django 使用 内置 content-type

    django内置的content-type组件, 记录了项目中所有model元数据的表 可以通过一个ContentType表的id和一个具体表中的id找到任何记录,及先通过ContenType表的id ...

  9. C++复制构造函数的实现

    复制构造函数是一种特殊的构造函数,有一般构造函数的特性.它的功能是用一个已知的对象来初始化一个被创建的同类对象.复制构造函数的参数传递方式必须按引用来进行传递,请看实例: #include <i ...

  10. 使用redis计数来控制单位时间内对某接口的访问量,防止刷验证码接口之类的

    使用自定义注解的方式,在需要被限制访问频率的方法上加注解即可控制. 看实现方式,基于springboot,aop,redis. 新建Springboot工程,引入redis,aop. 创建注解 pac ...