cookie中key值JSESSIONID,被后端登录响应setcookie 设置为HttpOnly,
估该cookie值 JSESSIONID 不允许被更改,导致setToken()出现未生效的现象。
import Cookies from 'js-cookie'
const TokenKey = 'JSESSIONID'
export function getToken() {
return Cookies.get(TokenKey)
}
export function setToken(token) {
return Cookies.set(TokenKey, token)
}
export function removeToken() {
return Cookies.remove(TokenKey)
}
import { getToken, setToken, removeToken } from '@/utils/auth'
// 登录
Login({ commit }, userInfo) {
const username = userInfo.username.trim()
const password = userInfo.password
const code = userInfo.code
const uuid = userInfo.uuid
return new Promise((resolve, reject) => {
login(username, password, code, uuid).then(res => {
setToken(res.token)
commit('SET_TOKEN', res.token)
resolve()
}).catch(error => {
reject(error)
})
})
},