关于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.冲突:如果你 ...
随机推荐
- 【Boost】boost库asio详解5——resolver与endpoint使用说明
tcp::resolver一般和tcp::resolver::query结合用,通过query这个词顾名思义就知道它是用来查询socket的相应信息,一般而言我们关心socket的东东有address ...
- Rotate List ,反转链表的右k个元素
问题描述: Given a list, rotate the list to the right by k places, where k is non-negative. For example:G ...
- js 验证 -身份证等
js验证身份证: function isIdCard(idCard) { var num = idCard.toLowerCase().match(/\w/g); if (idCard.match(/ ...
- H5手机端按钮点击一次却触发了多次点击事件
方案:在点击事件方法中加入以下语句 event.stopPropagation();
- python基础之字符编码(一)
一.什么是字符编码 计算机要想工作必须通电,也就是说‘电’驱使计算机干活,而‘电’的特性,就是高低电压(高低压即二进制数1,低电压即二进制数0),也就是说计算机只认识数字 编程的目的是让计算机干活,而 ...
- 2017.10.26 ECN + product spec+ cypress ble module test+
1 ECN Ecn should be issued when modifying drawing,Copy children BOM of subassembly from BIL if one ...
- iOS7.1以后企业应用发布需要HTTPS协议,解决步骤
操作系统是Window下. 第一步安装软件 1.安装Tomcat6.0.35(Tomcat7.0.34测试通过) 2.安装JDK6(1.6.0_10-rc2,其它版本没测试) 3.安装openssl ...
- Python爬虫--抓取糗事百科段子
今天使用python爬虫实现了自动抓取糗事百科的段子,因为糗事百科不需要登录,抓取比较简单.程序每按一次回车输出一条段子,代码参考了 http://cuiqingcai.com/990.html 但该 ...
- js 获取服务器当前时间
//获取服务器时间 function getNowDate(){ var xhr = null; if(window.XMLHttpRequest){ xhr = new window.XMLHttp ...
- html中<video>显示视频的时候,MP4的格式问题
html支持的视频格式:HTML5视频 注意 浏览器对mp4 的编码方式要求的非常严格 视频编码必须是H.264 音频编码必须是: AAC