1.在前台项目src文件夹下新建utils文件夹

    2.在utils目录下新建authority.js文件
    image.png
    3.authority.js内代码如下,主要用来处理token。

    1. export function setAuthority(access_token, refresh_token, expireTime) {
    2. localStorage.setItem('access_token', access_token);
    3. localStorage.setItem('refresh_token', refresh_token);
    4. localStorage.setItem('expireTime', `${expireTime}`);
    5. }
    6. export function getAccessToken() {
    7. return localStorage.getItem('access_token');
    8. }
    9. export function getRefreshToken() {
    10. return localStorage.getItem('refresh_token');
    11. }
    12. export function getTokenExpireTime() {
    13. return localStorage.getItem('expireTime');
    14. }
    15. export function clearToken() {
    16. localStorage.removeItem('access_token');
    17. localStorage.removeItem('refresh_token');
    18. localStorage.removeItem('expireTime');
    19. }