localStorage.js 821 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * @Description:
  3. * @Author: 欧阳承珺
  4. * @LastEditors: 欧阳承珺
  5. * @Date: 2022-10-26 09:30:22
  6. * @LastEditTime: 2022-11-16 13:54:28
  7. */
  8. import createPersistedState from 'vuex-persistedstate'
  9. import * as Cookies from 'js-cookie'
  10. import cookie from 'cookie';
  11. export default ({store, req}) => {
  12. createPersistedState({
  13. storage: {
  14. getItem: (key) => {
  15. if (process.server) {
  16. const parsedCookies = cookie.parse(req.headers.cookie);
  17. return parsedCookies[key];
  18. } else {
  19. return Cookies.get(key);
  20. }
  21. },
  22. setItem: (key, value) => Cookies.set(key, value, { expires: 15, secure: false }),
  23. removeItem: key => Cookies.remove(key)
  24. }
  25. })(store);
  26. }