使用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.dataconsole.log(this.banner)})
2 回答

拉莫斯之舞
TA贡献1820条经验 获得超10个赞
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)});}})

明月笑刀无情
TA贡献1828条经验 获得超4个赞
proxyTable可以解决问题。亲测以下问题可以完美解决:后台接口与本地的不在同一个地址下(跨域),用了proxyTable后就可以了,无需其他配置。如果是脚手架项目,在config/index.js里配置
添加回答
举报
0/150
提交
取消