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[,data,[選項]])
lightings.post(url[,數據,[選項]])
lightings.jsonp(url[,data,[選項]])
筆記:
config:true
屬性,例如 lightings.get('test.json',{
config:true,
...
});
timeout
、 progress
options
(可配置項)timeout
配置項目。 (jsonp不支援超時)progress
配置項目。 (jsonp不支援超時)修復低瀏覽器Promise
功能
修改lightings API,取消一些過時的配置
優化模板渲染