lightings
1.0.0
中文档 | ภาษาอังกฤษ
เฟรมเวิร์ก Ajax ที่มีน้ำหนักเบาซึ่งอิงตาม ES6 Promise
รองรับการเรนเดอร์เทมเพลต
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
เคล็ดลับ :ตัวอย่างการใช้ข้อมูล 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 ยกเลิกการกำหนดค่าที่ล้าสมัยบางอย่าง
การแสดงผลเทมเพลตที่ปรับให้เหมาะสม