vue-stash icon indicating copy to clipboard operation
vue-stash copied to clipboard

some way to add keys to store

Open fend25 opened this issue 6 years ago • 1 comments

Hi! Very nice library and I am using it for a long time. Thank you! One question: is there any way to add new key or sub key to store? Maybe something like store.$set('key.subkey', value)?

fend25 avatar Sep 25 '18 16:09 fend25

I found a solution.

First, make the root vue component accessible (for example, via window)

window.$root = new Vue({
el: ...,
data: {store},
...
})

Then, use normal vue's $set method:

$root.$set($root.store, 'key', value)
//or, for a second level:
$root.$set($root.store.key, 'otherKey', value)

And we are able again to access the store: store.key.otherKey = 'anotherValue' then vue re-renders fine and completely itself, no any $forceUpdate needed.

@cklmercer, I could extend the readme with this approach. Are you interested?

fend25 avatar Oct 05 '18 14:10 fend25