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);
});