cookie.js 718 B

12345678910111213141516171819202122232425262728293031
  1. /*
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-11-11 11:27:09
  6. * @LastEditTime: 2022-11-11 11:43:25
  7. */
  8. const Cookies = require('js-cookie')
  9. export function getToken (TokenKey) {
  10. return Cookies ? Cookies.get(TokenKey) : ''
  11. }
  12. export function setToken (TokenKey, token) {
  13. return Cookies && Cookies.set(TokenKey, token)
  14. }
  15. export function removeToken (TokenKey) {
  16. return Cookies && Cookies.remove(TokenKey)
  17. }
  18. // 解析cookie中的参数
  19. export function cookieParse (cookie) {
  20. if (!cookie) { return {} }
  21. const cookies = {}
  22. cookie.split(';').forEach(item => {
  23. const parts = item.split('=')
  24. cookies[parts[0].trim()] = parts[1].trim()
  25. })
  26. return cookies
  27. }