引入axios.js
methods里面:
send(){
axios({
method:'get',
url:'这里是请求地址,不方便透露了'
}).then(function(resp){
console.log(resp);
}).catch(resp => {
console.log('请求失败');
});
},
控制台报错 No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://xxx.com' is therefore not allowed access.
用jquery的$.getJSON() 可以正常请求
跨域请求
header
需要配置Access-Control-Allow-Origin
:跨域CORS另外
webpack-dev-server
可以配置代理proxy
的, 这样接口端不需要多做处理:devserver-proxy