2. axios的使用

1. 是什么

axios是基于promise對ajax的一種封裝。

2. 跨域

3. 生命周期問題

  1. created(){}在沒有顯示之前執行的方法。在這個時間一般是調用方法得到數據。

4 過程

(1)安裝axios

yarn add axios

(2)發送請求
默認使用方式是get請求

axios('http://localhost:3001/log').then(res=>{
   console.log(res);
}  

發送get請求

axios.get('http://localhost:3001/log').then(res=>{
   console.log(res);
}  

發送post參數請求

axios.post('http://localhost:3001/log').then(res=>{
   console.log(res);
}  
//axios的post請求默認使用application/json的方式進行發送。res拿不到數據的。
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容