如果我在服务器端设置了
感谢您的选择。
谢谢。
XSRF-TOKEN
cookie,是否需要设置任何内容来发送X-XSRF-TOKEN
头? 根据https://github.com/axios/axios/blob/master/lib/defaults.js#L74和https://github.com/axios/axios/blob/master/dist/axios.js#L1072,好像不需要设置,但我没有看到头部发送出去。同时我已将withCredentials
设置为true,因此我符合OR中的第一个检查条件。var xsrfValue = (config.withCredentials || isURLSameOrigin(config.url)) && config.xsrfCookieName ?
cookies.read(config.xsrfCookieName) :
undefined;
if (xsrfValue) {
requestHeaders[config.xsrfHeaderName] = xsrfValue;
}
因此,如果config.xsrfCookieName
是默认值.....
更新:
所以,我的OPTIONS
预检请求的CORS
已经可以使用,现在也可以使用POST
请求,但是没有发送X-XSRF-TOKEN
。
methods: {
onSubmit(e) {
this.axios
.post(
e.target.action,
{ data: this.form },
{
withCredentials: true,
xsrfCookieName: "XSRF-TOKEN",
xsrfHeaderName: "X-XSRF-TOKEN"
}
)
.then(res => {
console.log(res)
})
.catch(err => {
this.errors.push(err)
})
}
}
感谢您的选择。
谢谢。