关于vue-resource跨域

使用sylius的API接口,用本地服务器,但是vue的resource的get一直访问不到
Responsetopreflightrequestdoesn'tpassaccesscontrolcheck:No'Access-Control-Allow-Origin'headerispresentontherequestedresource.Origin'http://localhost:8080'isthereforenotallowedaccess.TheresponsehadHTTPstatuscode404.这段是关于报错!
this.$http.get('http://localhost:8000/api/ban...',{
headers:{'Content-Type':'application/json'}
}).then((response)=>{
this.banner=response.data
console.log(this.banner)
})
MMMHUHU
浏览 384回答 2
2回答

拉莫斯之舞

No'Access-Control-Allow-Origin',看这个像是跨域问题呀,用jsonp方法newVue({ready(){this.$http.jsonp('/url',{name:"abc"}).then(function(res){console.log(res)},function(res){console.log(res)});}})

明月笑刀无情

proxyTable可以解决问题。亲测以下问题可以完美解决:后台接口与本地的不在同一个地址下(跨域),用了proxyTable后就可以了,无需其他配置。如果是脚手架项目,在config/index.js里配置
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript