StorageController.weapp.js 557 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. /**
  3. * @flow
  4. * @private
  5. */
  6. const StorageController = {
  7. async: 0,
  8. getItem(path /*: string*/) /*: ?string*/{
  9. return wx.getStorageSync(path);
  10. },
  11. setItem(path /*: string*/, value /*: string*/) {
  12. try {
  13. wx.setStorageSync(path, value);
  14. } catch (e) {
  15. // Quota exceeded
  16. }
  17. },
  18. removeItem(path /*: string*/) {
  19. wx.removeStorageSync(path);
  20. },
  21. getAllKeys() {
  22. const res = wx.getStorageInfoSync();
  23. return res.keys;
  24. },
  25. clear() {
  26. wx.clearStorageSync();
  27. }
  28. };
  29. module.exports = StorageController;