同一浏览器使用的 Cookie 是相同的,第二个用户登录时,将会覆盖第一个用户的登录信息。不能存放在 Cookie 内,这样不能唯一区分用户,所以将Cookies改成localStorage
import Cookies from 'js-cookie'
const TokenKey = 'Admin-Token'
export function getToken() {
return localStorage.getItem(TokenKey)
}
export function setToken(token) {
return localStorage.setItem(TokenKey, token)
}
export function removeToken() {
return localStorage.removeItem(TokenKey)
}
if (this.loginForm.rememberMe) {
localStorage.setItem("phoneNumber", this.loginForm.phoneNumber, { expires: 30 });
// localStorage.setItem("username", this.loginForm.username, { expires: 30 });
localStorage.setItem("password", encrypt(this.loginForm.password), { expires: 30 });
localStorage.setItem('rememberMe', this.loginForm.rememberMe, { expires: 30 });
} else {
localStorage.removeItem("phoneNumber");
// localStorage.removeItem("username");
localStorage.removeItem("password");
localStorage.removeItem('rememberMe');
}