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拿不到数据的。
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容