getCookie.js 608 B

123456789101112131415161718192021222324
  1. import Cookie from 'js-cookie'
  2. export default {
  3. // 获取服务端cookie
  4. getcookiesInServer: function (req) {
  5. console.log('get server cookie')
  6. const service_cookie = {}
  7. req &&
  8. req.headers.cookie &&
  9. req.headers.cookie.split(';').forEach(function (val) {
  10. const parts = val.split('=')
  11. service_cookie[parts[0].trim()] = (parts[1] || '').trim()
  12. })
  13. return service_cookie
  14. },
  15. // 获取客户端cookie
  16. getcookiesInClient: function (key) {
  17. if (Cookie.get('can-use-cookie')) {
  18. return Cookie.get(key) || ''
  19. } else {
  20. return ''
  21. }
  22. },
  23. }