使用 TypeScript 来对原生的window.localstorage 进一步的封装,以便更好的使用
npm install ts-better-storage -D
通过import方式来调用插件,实例化后方可使用
import BetterStorage from "ts-better-storage";
const betterstorage = new BetterStorage()
// or
const betterstorage = new BetterStorage('key') // 实例时传入key,实现全局定义
获取缓存,get()
const betterstorage = new BetterStorage()
betterstorage.get('key')
// or
const betterstorage = new BetterStorage('key')
betterstorage.get()
设置缓存,set()
const betterstorage = new BetterStorage()
betterstorage.set('key','value')
// or
const betterstorage = new BetterStorage('key')
betterstorage.set('value')
移除某项, remove()
const betterstorage = new BetterStorage()
betterstorage.remove('key')
// or
const betterstorage = new BetterStorage('key')
betterstorage.set('value')
清除所有, clear()
const betterstorage = new BetterStorage()
betterstorage.clear()
获取所有,getAll()
const betterstorage = new BetterStorage()
betterstorage.getAll()