小程序端工程代码
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
664 B

  1. function localStorage() {
  2. return window.localStorage;
  3. }
  4. function get(key) {
  5. return JSON.parse(localStorage().getItem(key));
  6. }
  7. function set(key, data) {
  8. return localStorage().setItem(key, JSON.stringify(data));
  9. }
  10. function all() {
  11. const data = {};
  12. for (var i = localStorage().length - 1; i >= 0; i--) {
  13. var key = localStorage().key(i);
  14. data[key] = get(key);
  15. }
  16. return data;
  17. }
  18. function remove(key) {
  19. return localStorage().removeItem(key);
  20. }
  21. function clearAll() {
  22. return localStorage().clear();
  23. }
  24. function has(key) {
  25. return localStorage().getItem(key) !== null;
  26. }
  27. export default {
  28. get,
  29. set,
  30. all,
  31. remove,
  32. clearAll,
  33. has
  34. };