Skip to content

Waavi/vue-wstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm version npm downloads GitHub stars Travis Coverage Status MIT License




WStorage by WAAVI

Introduction

Vue WStorage is a library to manage localStorage and sessionStorage of your browser.

Install

npm install vue-wstorage --save

or

yarn add vue-wstorage

Install

import VueWStorage from 'vue-wstorage'

Vue.use(VueWStorage)
// Or you can specify any other name and use it via this.$ls, this.$whatEverYouWant
Vue.use(VueWStorage, {
  name: 'ls',
  key: 'app:0.0.1',
  storage: 'local', // Select session|local storage. By default it's 'local'
})

Usage

  • Global instance
// Use localStorage from object
Vue.storage.set('user', { name: 'Foo', surname: 'Demo' })
Vue.storage.get('user')

// Get all values
Vue.storage.get()
// Fallback value if nothing found in localStorage
Vue.storage.get('propertyThatNotExists', 'fallbackValue') // Will return 'fallbackValue' string

// Remove value
Vue.storage.remove('user')
// Remove all values
Vue.storage.clean()
  • Local instance
import VueWStorage from 'vue-wstorage'

const storage = VueWStorage.initalize()
storage.set('user', { name: 'Foo'})
storage.get('user')

storage.local.set('todos', [])
storage.session.set('step', 1)
  • Component
var vm = new Vue({
  methods: {
    handleUser () {
      this.$storage.set('loading', true)
      this.$storage.get('user')
      this.$storage.remove('loading')
    }
  }
})

License

MIT Licensed | Copyright © 2019-present Waavi Studio S.L.

About

Vue LocalStorage and SessionStorage manager

Resources

Stars

Watchers

Forks

Packages

No packages published