getCookie.js 488 B

1234567891011121314151617
  1. import Cookie from 'js-cookie'
  2. export default {
  3. //获取服务端cookie
  4. getcookiesInServer:function (req) {
  5. let service_cookie = {};
  6. req && req.headers.cookie && req.headers.cookie.split(';').forEach(function (val) {
  7. let parts = val.split('=');
  8. service_cookie[parts[0].trim()] = (parts[1] || '').trim();
  9. });
  10. return service_cookie;
  11. },
  12. //获取客户端cookie
  13. getcookiesInClient:function (key) {
  14. return Cookie.get(key) ? Cookie.get(key) : ''
  15. }
  16. }