enhanced localStorage(加强版 localStorage)
npm i k-localstorage
or
pnpm i k-localstorage
For Vue Project in main.js add
import 'k-localstorage'
create a storage.config.js
module.exports = {
storagePrefix: '',
localStorageWhiteList: [],
}
storagePrefix
: addPrefix (在普通 key 上添加前缀)
localStorageWhiteList
: localStorage.clean() will skip array (使用 localStorage.clean()时会跳过里面的值)
then you can use it as native localStorage
localStorage.a = '1'
localStorage.setItem('a', '2')
localStorage.a
localStorage.getItem('a')
localStorage.removeItem('a')
localStorage.clean() // only clean add storagePrefix and skip localStorageWhiteList (只会清除添加了storagePrefix值的前缀,会跳过localStorageWhiteList白名单里的值)