Is there a way to add Vuex to Vue plugin install function and share state between its components?
Custom component properties are supposed to be globally provided in Vue 2 by assigning them to Vue.prototype
because component instances prototypically inherit from it.
new Vuex.Store(store)
is a mistake if store
is already Vuex store and not plain object that contains store options. This will result in malfunctioning store like shown in this question. Even if store
is not store instance yet, it makes sense to make it an instance and export in a separate module so it could be imported in non-component modules.
It should be:
Vue.prototype.$store = store