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拿不到数据的。