0.1.4 • Published 5 years ago
@mu-ui/mu-storage v0.1.4
mu-storage
a simple storage plugin for vue 2.x to use localStorage & sessionStorage.
Installation
yarn add @mu-ui/mu-storage
Usage
import Storage from '@mu-ui/mu-storage'
Vue.use(Storage)
Example
// localStorage
this.$storage.set('name', 'JR')
Vue.storage.get('name')
// sessionStorage
this.$session.set('name', 'JR')
Vue.session.get('name')
Api
set(key, val)
set storage with key and val
get(key)
get storage with key
remove(key)
remove storage with key
has(key)
determine storage has the key
clearAll()
clear all storages
forEach(callback)
forEach the storages and call the callback function with each storage
filter(callback(key))
create a array with all storages that pass the test implemented by the provided function. If no storages pass the test, an empty array will be returned. If don't provide a callback function, a array with all storages will be returned.
callback
Function is a predicate, to test each storage of the storages. Return true to keep the storage, false otherwise. It accepts one arguments:
key
key of the current storage
const arr = this.$storage.filter(key => {
return key === 'name'
})
console.log(arr) // [{key: 'name', val: 'JR'}]