背景资料:
前端域名:http://a.xxx.com
后端域名:http://b.xxx.com
基于vue-resouce v0.9.3发送的ajax
我所知道的
搜索了资料,我所知道的要点如下:
1.后端需要设置
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:*
Access-Control-Allow-Origin:http://a.xxx.com
2.前端需要设置
2.1设置credentials
xhr.withCredentials: true
对应vue-resource v0.9.3的
this.$http.post(
"b.xxx.com/test",
{},
{
credentials: true
}
).then(....)
2.2设置cookie
document.cookie="token=xxxxxxxxxxxxxxxx;domain=xxx.com;path=/"
2.3vue-resource头部重置
默认的vue-resource对头部设置的content-type有默认设置,但是我已经重置了
Vue.http.headers.common={};
Vue.http.headers.post={};
问题
我所列出的前端设置和后端设置都弄好了,检查过也没有问题。
可是我在chrome的devtool的network面板,没有看到request带上cookie。
我估计是vue-resource的问题?
心塞,求指导
==================UPDATE=======================
1,用jquery替代vue-resource,是可以的。就是说我配置的跨域cookie是没问题的
2.我还找不到vue-resource出了什么问题不能发送cookie,已经确认开启credentials参数的生效的,但是就是发不出cookie
你配置错了,它本身没有问题