You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
985 B

5 months ago
  1. /**
  2. * 封装操作localstorage本地存储的方法
  3. */
  4. export const storage = {
  5. //存储
  6. set(key, value) {
  7. localStorage.setItem(key, JSON.stringify(value))
  8. },
  9. //取出数据
  10. get(key) {
  11. const value = localStorage.getItem(key)
  12. if (value && value != 'undefined' && value != 'null') {
  13. return JSON.parse(value)
  14. }
  15. },
  16. // 删除数据
  17. remove(key) {
  18. localStorage.removeItem(key)
  19. }
  20. }
  21. /**
  22. * 封装操作sessionStorage本地存储的方法
  23. */
  24. export const sessionStorage = {
  25. //存储
  26. set(key, value) {
  27. window.sessionStorage.setItem(key, JSON.stringify(value))
  28. },
  29. //取出数据
  30. get(key) {
  31. const value = window.sessionStorage.getItem(key)
  32. if (value && value != 'undefined' && value != 'null') {
  33. return JSON.parse(value)
  34. }
  35. return null
  36. },
  37. // 删除数据
  38. remove(key) {
  39. window.sessionStorage.removeItem(key)
  40. }
  41. }