- 官方文档:https://axios-http.com/zh/
安装
npm install axios --save
基本使用
axios库的使用非常简单,简单浏览一下官网即可了解个大概。
发起一个get请求
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// 总是会执行
});
发起一个post请求
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
实际使用
现在我们先用他来实际用到我们项目中,采用向后台发起请求的方式获取博客的分类数据: