1、axios库的使用
什么是axios?
axios:ajax + i/o + system
axios的作用
主要作用于发送请求的等。
axios是目前前端使用非常广泛的网络请求库,包括Vue作者也是推荐在vue中使用axios
响应、转换请求和响应数据等等;
主要特点包括︰在浏览器中发送XMLHttpRequests请求、在node.js中发送 http请求、
支持Promise API、拦截请求和响应数据等。
2、axios的基本使用(promise)
安装axios
npm install axios
使用axios发送get/post请求
javascript
/**
* 使用get请求
*/
axios({
url:'http://httpbin.org/get',
params:{
name:'kjh',
age:29
},
method:'get'
}).then(
res => console.log(res)
).catch(
err => console.error(err)
)
/**
* 使用post请求
*/
axios({
url:'http://httpbin.org/post',
data:{
name:'123',
time:'2019-09-09'
},
method:'post'
}).then(
res => console.log(res)
).catch(
err => console.error(err)
)