使用vue时,发送请求不带cookie

第一次使用VUE进行开发,在获取图片验证码与服务器进行比对时,提示验证码错误,最后发现请求时未携带cookie,导致SESSIONID改变致使校验失败.

解决办法

Vue.http.options.emulateJSON = true;
Vue.http.options.xhr = { withCredentials: true }

//在拦截其中添加此属性即可
Vue.http.interceptors.push((request, next) => {
request.credentials = true
next()
})

//axios设置

axios.defaults.withCredentials=true

posted on 2017-04-11 08:31  oldcowstruggle  阅读(2205)  评论(0编辑  收藏  举报