axios
更全面的大家了解https://www.cnblogs.com/libin-1/p/6607945.html
他就是帮助我们请求数据获取发送数据的一个桥梁。基于promise用于浏览器和node.js
Axios 是一个基于 promise 的 HTTP 库,可以用在浏览器和 node.js 中。
axios的过程
从浏览器中创建 XMLHttpRequests
从 node.js 创建 http 请求
支持 Promise API
拦截请求和响应
转换请求数据和响应数据
取消请求
自动转换 JSON 数据
客户端支持防御 XSRF
如何引入
1.通过npm install axios
2.
get请求
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
// 可选地,上面的请求可以这样做
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
post请求
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});