1.0.2 • Published 4 years ago

umbrella-storage v1.0.2

Weekly downloads
86
License
MIT
Repository
github
Last release
4 years ago

umbrella

umbrella of localStorage & sessionStorage between web apps

codecov travis-ci

说明

一个操作localStorage和sessionStorage的插件,避免同一个域名下部署不同前端web app,本地存储使用同样的key导致的冲突问题。

默认会使用域名+路径作为前缀(适用于hashRouter),对于BrowserRouter可以使用自定义前缀配置。

安装

yarn add umbrella-storage

使用

import umbrella from 'umbrella-storage';

umbrella.setLocalStorage('test', 'test');
umbrella.getLocalStorage('test');

umbrella.setSessionStorage('sessionTest', { name: 'test' });
umbrella.getSessionStorage('sessionTest');

API

// 配置自定义前缀
umbrella.config(prefix: string);

// 操作localStorage,value不需要转成字符串,自动帮忙处理
umbrella.setLocalStorage(key, value);
umbrella.getLocalStorage(key);
umbrella.removeLocalStorage(key);

// 操作localStorage,value不需要转成字符串,自动帮忙处理
umbrella.setSessionStorage(key, value);
umbrella.getSessionStorage(key);
umbrella.removeSessionStorage(key);