美文网首页
2. axios的使用

2. axios的使用

作者: 哥是八路 | 来源:发表于2021-04-26 13:59 被阅读0次

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

相关文章

网友评论

      本文标题:2. axios的使用

      本文链接:https://www.haomeiwen.com/subject/duetrltx.html