默认情况下withCredentials为false。
axios默认是请求的时候不会带上cookie的,需要通过设置 withCredentials:true来解决。
1、全局设置withCredentials为true,在axios封装里设置
axios.defaults.withCredentials=true;
2、单个请求设置withCredentials为true(有其他请求需要withCredentials:false时)
例子:
login(params) {
return axios.post(`${base.url}auth/user/userLogin`, params,{withCredentials:true});
},
在登录请求的时候,widthCredentials为true时后台才会计算登录次数,根据错误的登录次数才可以计算何时获取验证码。
注意:后台服务端需要设置响应头。