一个简单好用的localstorage组件store

我们知道 localstorage value接收的是一个字符串,所以存取值如果是一个对象时,使用起来就很麻烦了,需要来回转化,所以这个组件就把这块做了封装,并把使用时的名字简化,不需要在 window.localstorage.setItem() ,只需要 store.set() 即可,可读性非常高

安装

npm install store

引入

import storage from 'store'

使用

// 赋值
storage.set('themeData', data)
// 取值
const localThemeData = storage.get('themeData')

猜你喜欢

转载自blog.csdn.net/weixin_34403976/article/details/125537641