smart-admin/smart-admin-web/src/lib/cookie.js
2020-01-11 09:10:29 +08:00

22 lines
489 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Cookies from 'js-cookie';
import config from '@/config';
const { cookieExpires } = config;
export const TOKEN_KEY = 'token';
export default {
setToken: token => {
Cookies.set(TOKEN_KEY, token, {
// token在Cookie中存储的天数默认1天
expires: cookieExpires || 7
});
},
getToken: () => {
const token = Cookies.get(TOKEN_KEY);
if (token) return token;
else return null;
},
clearToken: () => {
Cookies.remove(TOKEN_KEY);
}
};