首页 > 微信 > 详细

小程序使用缓存

时间:2019-08-26 11:34:35      阅读:117      评论:0      收藏:0      [点我收藏+]

设置缓存

wx.setStorage({
  key:"key",
  data:"value"
})

移除缓存

wx.removeStorage({
  key: 'key',
  success (res) {
    console.log(res)
  }
})

获取缓存

wx.getStorage({
  key: 'key',
  success (res) {
    console.log(res.data)
  }
})

清理缓存

wx.clearStorage()

封装一个Storage

export default {
  set: (data, key = 'userData') => {
    return wx.setStorageSync(key, data);
  },
  get: (key = 'userData') => {
    return wx.getStorageSync(key);
  },
  remove: (key = 'userData') => {
    return wx.removeStorageSync(key);
  },
  clear: () => {
    return wx.clearStorageSync();
  },
  Set: (data, key = 'userData') => {
    return wx.setStorage({ key, data });
  },
  Get: (key = 'userData') => {
    return wx.getStorage({ key });
  },
  Remove: (key = 'userData') => {
    return wx.removeStorage(key);
  },
  Clear: () => {
    return wx.clearStorage();
  }
};

使用封装

import Storage from "./common/auth/Storage";
const storage = Storage.get("userData");
if (!storage) {
    return that.login_register();
}

小程序使用缓存

原文:https://www.cnblogs.com/jiqing9006/p/11411086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!