compatible-storage
v0.3.1
Published
> Support all browser, Wechat mini program and Alipay mini program. > 支持所有浏览器的硬盘缓存,同时支持微信小程序和支付宝小程序。
Downloads
24
Maintainers
Readme
Compatible-Storage
Support all browser, Wechat mini program and Alipay mini program. 支持所有浏览器的硬盘缓存,同时支持微信小程序和支付宝小程序。
Quick to set, get and remove the storage. 简易的get、set操作。
NPM
Install 安装
npm i -save compatible-storage
// or
yarn add compatible-storage
Import 导入
import StorageUtils from 'compatible-storage';
Usage 使用
Storage 硬盘缓存
// Set by default expire time. Default: 30 days.
StorageUtils.set('storage-key', { ...data...});
// Custom expire time. eg: 2 hours.
StorageUtils.set('storage-key', { ...data...}, new StorageUtils.Expire(2, StorageUtils.EXPIRE_UNIT.HOUR));
// Get
const value = StorageUtils.get('storage-key');
// Remove
StorageUtils.remove('storage-key');
Memory 内存缓存
It will be reset when your shut down the mini-program or close the web window. 当退出小程序或关闭网页,数据会重置
// Set by default expire time. Default: 30 days.
StorageUtils.setMemory('storage-key', { ...data...});
// Custom expire time. eg: 2 hours.
StorageUtils.setMemory('storage-key', { ...data...}, new StorageUtils.Expire(2, StorageUtils.EXPIRE_UNIT.HOUR));
// Get
const value = StorageUtils.getMemory('storage-key');
// Remove
StorageUtils.removeMemory('storage-key');
// Reference object 获取引用对象
// Wechat Mini-Program 微信小程序
const memory = wx[StorageUtils.KEY_MEMORY]
// Alipay Mini-Program 支付宝小程序
const memory = my[StorageUtils.KEY_MEMORY]
// Web Page 网页
const memory = window[StorageUtils.KEY_MEMORY]
// Get value for reference object 通过引用对象获取指定键的值
const value = memory[key]