vue-resource Content-Type is not allowed by Access-Control-Allow-Headers in preflight response

 朋友刚问了一个问题


用JQuery Ajax 请求的时候没有问题,正常请求该接口。

但是换成vue-resouce 时会报如上的错。


后来经过查找发现时 发现是Content-type 问题

vue-resource 请求时候 requests encoded 为 application/json

jquery 请求时候 requests encoded 为 application/x-www-form-urlencoded


所以我们可以让vue-resouece 提交数据的编码和jquery是一样的

在main.js中  设置 Vue.http.options.emulateJSON = true;

还有一种方法是在后台设置 Access-Control-Allow-Headers : Content-Type


下面是vue-resouece 提到的解决方案



地址https://github.com/pagekit/vue-resource/blob/master/docs/config.md#legacy-web-servers


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值