Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
Features
从 node.js 创建 http 请求
拦截请求和响应
转换请求数据和响应数据
取消请求
自动转换 JSON 数据
客户端支持防御 XSRF
//get请求第一种写法
axios({
method: 'get',
url: 'https://ipinfo.io',
params: {
ID: 12345 //参数
}
})
.then(function(response) {
console.log(response.data);
});
//get请求第二种写法
var result = axios({
method: 'get',
url: 'https://ipinfo.io',
params: {
ID: 12345
}
});
result.then(function(response) {
console.log(response.data);
});
//post请求
axios({
method: 'post',
url: 'https://ipinfo.io',
data: {
ID: 12345 //参数
}
})
.then(function(response) {
console.log(response.data);
});