axios发送ajax请求
支持IE8以上
npm install axios
get请求
axios.get('url')
.then(res => {
axios将数据封装到data中
console.log(res.data);
})
.catch(error => {
console.log(error)
})
post请求
axios.post('url',{要传入的参数})
.then(res => {
axios将数据封装到data中
console.log(res.data);
})
.catch(error => {
console.log(error)
})
注意:axios不支持跨域请求,
之所以使用get和post发送跨域请求的时候能够获取到数据,是因为后台帮我们做了响应头的处理
Access-Control-Allow-Origin:* // 允许所有的域
Access-Control-Allow-Methods:* // 允许所有的方法
注意:
vue-resource,vue官方文档已经不推荐使用了,并且已经停止维护了