Frisbee介紹
這是GitHub上JavaScript一款網絡請求架構,使用友善,很大程度簡化了react原始的網絡請求方式,倉庫位址:https://github.com/joinspontaneous/frisbee
使用
-
下載下傳
nmp方式:指令行執行npm install --save frisbee
-
引入
在JavaScript檔案中引用import Frisbee from 'frisbee'
-
使用
/**
* 先抽取成全局變量
* 網絡工具
**/
const api = new Frisbee({
baseURI: '你的url根位址',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Accept-Charset': 'utf-8',
'Method': 'GET',
}
let data = await api.get('具體的url位址');
//data就是方法傳回的資料對象,body屬性就是具體的json内容
console.log(data.body);
});