Parse Platform

修改Parse-SDK-JS之旅:localStorage存储

2017-05-25  本文已影响0人  NextStack

这里修改是比较简单的

定位脚本

文件名src/StorageController.browser.js显而易见,就是它了!

修改脚本

修改脚本很简单,把原生的localStorage API改为微信小程序的api即可:

import ParsePromise from './ParsePromise';

var StorageController = {
  async: 0,

  getItem(path: string): ?string {
    // return localStorage.getItem(path);
    return wx.getStorageSync(path);
  },

  setItem(path: string, value: string) {
    try {
      // localStorage.setItem(path, value);
      wx.setStorageSync(path, value);
    } catch (e) {
      // Quota exceeded, possibly due to Safari Private Browsing mode
    }
  },

  removeItem(path: string) {
    // localStorage.removeItem(path);
    return wx.removeStorageSync(path);
  },

  clear() {
    // localStorage.clear();
    return wx.clearStorageSync();
  }
};

module.exports = StorageController;

测试,完美!

上一篇下一篇

猜你喜欢

热点阅读