vue-reactivestorage

Reactive layer for interacting with localStorage from Vue.
1,283 126
Install
npm install vue-reactivestorage
Latest Version:1.3.0
License:ISC
Last Updated:Jun 14, 2018
Links: GitHub  ·  npm
Maintainer: rop

vue-reactivestorage

Reactive layer for interacting with localStorage from Vue. Plugin for Vue 2.

why

window.localStorage cannot be reactive if you use it directly with Vue, ex


new Vue({
    data {
      localStorage: window.localStorage
    },
    template: " <div> {{localStorage.notes}}, {{localStorage.lang}} ... </div> ",
    created: function() {
        this.localStorage.lang = "other value";
    }
})

Code above will not react, even bind to view. So...

how to use

import reactiveStorage from "vue-reactivestorage";

Vue.use(reactiveStorage, [
    "notes", 
    "lang",
    "name",
    "foo"
]); 

Define vars that will be stored and proxied by Vue (any other var in window.localStorage that is not on this array will not be proxied).

Now you can acess the namespace localStorage in Vue.

new Vue({
    template: " <div> {{localStorage.notes}}, {{localStorage.lang}} ... </div> ",
    created: function() {
        this.localStorage.lang = "other value"; // will react on the view and on real localStorage.
    }
})

Related Packages

vue-local-cache

兼容 Vue2 与 Vue3 的本地缓存插件,支持前缀、自动过期、按页面(vue-router)命名空...

659
@morgul/snowpack-plugin-vue2

A snowpack vue2 compiler based on `@snowpack/plugin-vue`.

9,507 6
vue2-dnd

Drag n' Drop plugin for Vue.js

2,111 12
@dullar/mercury

Advanced and highly reusable Mobile UI Components built on Vue2 & You can define...

8,553 6
@vitely/vue2

Vitely for vue 2.7

2,251 0

Version History

Version Released License
1.3.0 ISC