1. 是什么
axios是基于promise對ajax的一種封裝。
2. 跨域
3. 生命周期問題
- 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拿不到數據的。