使用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

原文地址:https://www.cnblogs.com/oldcownotGiveup/p/6691870.html