Axios 是一个基于 promise 的 HTTP 库,通过promise实现对ajax技术的一种封装,就像jQuery实现ajax封装一样。
1.传入配置发起请求
axios({
url: '接口地址',
method: 'get', // 或者post请求类型
responseType: 'json', //默认格式json
data: {
'username' : 'hx',
'password' : '123'
}
}).then( function(response){ // 请求正确返回的数据
console.log(response);
console.log(response.data);
}).catch( function(error) { // 请求错误返回的数据
console.log(error);
})
2.Get请求
// 为给定 ID 的 user 创建请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(f