lightings
1.0.0
中文文档 |英语
一个基于ES6 Promise
轻量级Ajax框架,支持模板渲染。
npm install lightings
lightings
|---src
| |---lightings.js (es6 source)
| |---promise.js (low browser support Promise)
|
|---dist
|---lightings.js (use bable compiler source code es5)
|---lightings.min.js
提示:如果您的浏览器支持ES6语法,可以直接在src目录下使用ES6源码。
Tip :JSON数据统一使用示例:
{
"name": "Lightings",
"author": {
"firstName": "Jay",
"lastName": "Zangwill"
}
}
执行 GET 请求(使用模板渲染)
lightings.get('test.json',{
config: true,
el: '#app'
}).then(function(data){
console.log(data);
//other operation
}).catch(function(error){
console.log(error);
});
<!-- html -->
<div id="app">
<p>author: {{author.firstName}} {{author.lastName}}</p>
<p>name: {{name}}</p>
</div>
执行 GET 请求(不使用模板渲染)
lightings.get('test.json')
.then(function(data){
console.log(data);
//dom operation and other operation
}).catch(function(error){
console.log(error);
});
跨域请求
lightings.jsonp('http://jayzangwill.cn/test.json')
.then(function(data){
console.log(data);
//dom operation and other operation
}).catch(function(error){
console.log(error);
});
lightings.get(url[,数据,[选项]])
lightings.post(url[,数据,[选项]])
lightings.jsonp(url[,数据,[选项]])
笔记:
config:true
属性,例如 lightings.get('test.json',{
config:true,
...
});
timeout
、 progress
options
(可配置项)timeout
配置项。 (jsonp不支持超时)progress
配置项。 (jsonp不支持超时)修复低浏览器Promise
功能
修改lightings API,取消一些过时的配置
优化模板渲染