saber-storage
v2.0.0
Published
移动端的本地存储,兼容node平台
Readme
saber-storage
移动端本地存储模块,提供 memory、session 与 local 三种存储模式,并且兼容 node 环境
Installation
通过 edp 引入模块:
$ edp import saber-storage或者在 node 环境下使用 npm 引入模块:
$ npm install saber-storage --saveUsage
var Storage = require('saber-storage');
// 使用localStorage进行本地存储
var storage = new Storage('local');
// 存入
storage.setItem('string', 'this is a string');
storage.setItem('object', {a: 1});
// {a: 1}
storage.getItem('object');API
Constructor
Storage(type)
- type
{string=}存储类型,支持以下取值:- memory 内存存储
- session
sessionStorage存储 - local
localStorage存储
node 环境下目前支持 memory 内存存储,可以做为 rebas 的插件提供基于内存的 session 数据存储
Methods
setItem(key, val)
存入数据
- key
{String}存储键名 - val
{*}对应键名下的数据
getItem(key)
根据键名返回数据
- key
{String}存储键名 - return
{*}对应键名下的数据
removeItem(key)
移除某键名下的数据
- key
{String}存储键名 - return
{void}
clear()
清空已持久化的数据
- return
{void}
key()
获得持久化数据的key
- return
{Array}键名数组
getAllItems()
获取所有存储的数据
- return
{Object}存储的数据
