关于sea.js的笔记
首先,引入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的笔记的更多相关文章
- js模块加载框架 sea.js学习笔记
seajs实现了JavaScript 的 模块开发及按模块加载.用来解决繁琐的js命名冲突,文件依赖等问题,其主要目的是令JavaScript开发模块化并可以轻松愉悦进行加载. 官方文档:http:/ ...
- sea.js模块化编程
* 为什么要模块化? 解决文件依赖 解决命名冲突 ; var var2 = 2; function fn1(){ } function fn2(){ } return { fn1: fn1, fn2: ...
- sea.js模块加载工具
seajs的使用 seajs是一个jS模块加载器,由淘宝前端架构师玉伯开发,它可以解决命名空间污染,文件依赖的问题.可以在一个js文件中引入另外一个js.require('a.js') 1.安装 np ...
- js学习笔记:webpack基础入门(一)
之前听说过webpack,今天想正式的接触一下,先跟着webpack的官方用户指南走: 在这里有: 如何安装webpack 如何使用webpack 如何使用loader 如何使用webpack的开发者 ...
- Vue.js学习笔记(2)vue-router
vue中vue-router的使用:
- 解决sea.js引用jQuery提示$ is not a function的问题
在使用sea.js的如下写法引用jQuery文件时, //main.jsdefine(function(require,exports,module){ var $ = require('jquery ...
- js读书笔记
js读书笔记 基本类型的基本函数总结 1. Boolean() 数据类型 转换为true的值 转换为false的值 Boolean true false String 任何非空字符串 "&q ...
- React.js入门笔记
# React.js入门笔记 核心提示 这是本人学习react.js的第一篇入门笔记,估计也会是该系列涵盖内容最多的笔记,主要内容来自英文官方文档的快速上手部分和阮一峰博客教程.当然,还有我自己尝试的 ...
- 模块化开发--sea.js
当你的网站开发越来越复杂的时候,会经常遇到一下问题吗?1.冲突2.性能3.依赖如果在多人开发或者是复杂的开发过程中会经常遇到这些问 题,就可以用模块化开发来解决.以上问题是如何产生的?1.冲突:如果你 ...
随机推荐
- POJ - 2785 - 4 Values whose Sum is 0 - 二分折半查找
2017-08-01 21:29:14 writer:pprp 参考:http://blog.csdn.net/piaocoder/article/details/45584763 算法分析:直接暴力 ...
- Reverse Nodes In K Group,将链表每k个元素为一组进行反转---特例Swap Nodes in Pairs,成对儿反转
问题描述:1->2->3->4,假设k=2进行反转,得到2->1->4->3:k=3进行反转,得到3->2->1->4 算法思想:基本操作就是链表 ...
- js 小秘密
1.RegExp 对象方法 test检索字符串中指定的值.返回 true 或 false. 支持正则表达式的 String 对象的方法
- Learining TypeScript (一) TypeScript 简介
Learining TypeScript (一) TypeScript 简介 一.TypeScript出现的背景 2 二.TypeScript的架构 2 1. 设计目标 2 2 ...
- C++(十八) — 内存模式、堆和栈
1.内存模式 一个程序执行时,先复制到内存,然后CPU逐句读取指令执行. 每个存储单元存放一个字节(8bit)数据,每个有一个唯一的地址,地址是顺序编码的.比如:一台计算机256MB内存,则有256* ...
- android多国语言使用
多国语言:在res目录下建立不同名称的values文件来调用不同的语言包 Values文件汇总如下: 中文(中国):values-zh-rCN 中文(台湾):values-zh-rTW 中文(香港): ...
- Sunday算法--C#版
public static int Sunday(string text, string pattern) { int i, j, m, k; i = j = 0; int tl, pl; int p ...
- html03表单
<!DOCTYPE HTML> <html> <head> <title>用户登录的表单</title> </head> < ...
- day13作业
#作业1猜年龄 , 可以让用户最多猜三次! # Auther:bing #!/usr/bin/env python age = 24 print("猜年龄") for i in r ...
- LeetCode OJ:First Missing Positive (第一个丢失的正数)
在leetCode上做的第一个难度是hard的题,题目如下: Given an unsorted integer array, find the first missing positive inte ...