我正在尝试从我的后端获取 CSRF 令牌。使用 fetch
时,我可以简单地
const response = await fetch(`/account/csrf/`, {
credentials: "include",
});
const data = await response
let csrfToken = data.headers.get("X-CSRFToken"); // how is this done with axios?
我试过了
const csrfToken = await this.$axios.$get(`/account/csrf/`, {
/*
what is the equivalent here?
I don't wish to *send* anything to the server, but rather retrieve, so I guess I can't use headers {}
*/
});
答案 0 :(得分:1)
您可以使用来自 Axios 的原始 $get()
方法,而不是使用来自 nuxt 模块的 get()
助手获取,如下所示:
const { data, headers } = await this.$axios.get('/account/csrf/', {
withCredentials: true
});
const csrfToken = headers["X-CSRFToken"];