今天在写登录模块的时候,登录的时候发现cookie获取不到登录的用户信息,打开开发者模式发现下面的警告的
submitLogin() {
// 第一步 调用接口进行登录,返回token字符串
loginApi.login(this.user).then((response) => {
//第二步 获取token字符串放到cookie里面
cookie.set("guli_token", response.data.data.token, {
domain: "localhost",
});
// 第四步 调用接口 根据token获取用户信息,为了首页显示
loginApi.getUcenterByToken().then((response) => {
this.loginInfo = response.data.data.ucenterMember;
//获取返回用户信息,放到cookie里面
cookie.set("guli_ucenter", this.loginInfo, { domain: "localhost" });
console.log(cookie.get("guli_ucenter"))
// 跳转页面
window.location.href = "/";
});
});
},
cookie中存放登录成功的用户信息然后在页面显示,测试时打印输出cookie.set("guli_ucenter")时里面没有数据,有什么办法可以解决