Closed driekus77 closed 6 years ago
Make sure you're passing store
when instantiating your root Vue instance.
Hi,
I'm experiencing the same (store
is passed properly) and it's also reproducible on your demo (https://vjo3xlpyny.codesandbox.io/). Everything works fine though.
I'm a complete vue newbie, but it seems to me as if the created
method is called too early. this.$store
doesn't exist there yet, then created
is called again and then this.$store
exists.
Just to help future users that might also find this problem: I managed to avoid the error by adding the module after creating the Vuex
instance and before creating the Vue
instance:
Vue.use(Vuex)
let store = new Vuex.Store({
state: {
val: 0
},
mutations: {
emptyState() {
this.replaceState({ val: 0 })
}
}
})
Vue.use(VuexUndoRedo)
new Vue({
store: store,
components: { App },
router,
template: '<App/>',
}).$mount('#app')
Sorry for the delay.
So the issue, as @claudiocabral has identified, is that you must install this plugin after you've installed Vuex and created a store.
I think I'm going to update the plugin so it will throw an error if you don't do this and provide an error message that explains it; I don't think there's any other way.
I'll also update the docs to explain this, too.
Hey,
I think improving the documentation to include that would help a lot too. I'll have a look at the code and see if I can come up with a solution, since this is a bit of a weird pattern, but I can see how it might be hard to change
I have mentioned it in the docs now. And yeah, open to a better solution if you have one.
Looks promising this Undo Redo component!
Unfortunately I get an error when add/uncommenting:
Vue.use(VuexUndoRedo)
Using Chrome browser I get:
Added the mutation emptyState in all the stores ( core and admin which are namespaced ).
My package.json:
Thanks for any help!