axios的使用

时间:2021-04-20 14:53:50   收藏:0   阅读:0

1.npm安装:npm install axios

2.axios发送请求后返回的是一个promise

3.axios发送get请求:

import axios from ‘axios‘;

axios.get(‘http://localhost:8080/getData?username=abc&id=1‘).then(res=>{

  console.log(res);

});

参数传递另一种写法:

import axios from ‘axios‘;

axios.get(‘http://localhost:8080/getData‘,{params:{id:1,username:‘abc‘}}).then(res=>{

  console.log(res);

});

4.axios发送post请求:

import axios from ‘axios‘;

axios.post(‘http://localhost:8080/postData‘,"name=张三&urs=test").then(res=>{

  console.log(res);

});

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!