0.1.4 • Published 5 years ago

@mu-ui/mu-storage v0.1.4

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

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'}]
0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago