朋友刚问了一个问题


用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


Logo

前往低代码交流专区

更多推荐