Javascript 即使';withCredentials:false';
因此,我正在用VueJS编写一个前端项目。我已经有一个定制的express后端服务于API。这不一定是个问题,但当我使用axios时,cookies会随请求一起传递;即使我默认设置了“withCredentials:false”和Javascript 即使';withCredentials:false';,javascript,vue.js,cookies,axios,Javascript,Vue.js,Cookies,Axios,因此,我正在用VueJS编写一个前端项目。我已经有一个定制的express后端服务于API。这不一定是个问题,但当我使用axios时,cookies会随请求一起传递;即使我默认设置了“withCredentials:false”和 <template> <div> <h1>Login Vue</h1> <input type="text" name="username&
<template>
<div>
<h1>Login Vue</h1>
<input
type="text"
name="username"
v-model="input.username"
placeholder="Username"
/>
<input
type="password"
name="password"
v-model="input.password"
placeholder="Password"
/>
<button type="button" v-on:click="login()">Login</button>
<button type="button" v-on:click="getMe()">GetMe</button>
</div>
</template>
<script>
import axios from 'axios';
export default {
name: 'HelloWorld',
props: {
msg: String,
},
data: function() {
return {
input: {
username: '',
password: '',
},
};
},
methods: {
login: async function() {
const user = await axios.post(
`/api/v1/users/login`,
{
username: this.input.username,
password: this.input.password,
},
{ withCredentials: true }
);
console.log(user);
},
getMe: async function() {
const me = await axios.get(`/api/v1/users/me`, {
withCredentials: false,
});
console.log(me);
},
},
};
</script>
如果我在GET请求的后端输入console.log req.cookies,我会得到:
{
authToken: 'RANDOM JSON TOKEN'
}
{
authToken: 'RANDOM JSON TOKEN'
}