1.在前台项目src文件夹下新建utils文件夹
2.在utils目录下新建authority.js文件
3.authority.js内代码如下,主要用来处理token。
export function setAuthority(access_token, refresh_token, expireTime) {
localStorage.setItem('access_token', access_token);
localStorage.setItem('refresh_token', refresh_token);
localStorage.setItem('expireTime', `${expireTime}`);
}
export function getAccessToken() {
return localStorage.getItem('access_token');
}
export function getRefreshToken() {
return localStorage.getItem('refresh_token');
}
export function getTokenExpireTime() {
return localStorage.getItem('expireTime');
}
export function clearToken() {
localStorage.removeItem('access_token');
localStorage.removeItem('refresh_token');
localStorage.removeItem('expireTime');
}