I am working on pagination part in a project for a large data. I wanted to store my data inside vuex. But i did all my logic in vuex store module. I wanted to reuse that particular module by creating an instance of it. Is it possible to create it ? or Creating an service would be better ? or a mixins can help by chance. But my main thing is that it should store that definitely in the store itself.
component1 -> new CommonStoreModule() component2 -> new CommonStoreModule()
Help me to follow which approch and pattern would be most suitable.
Advertisement
Answer
As the documentation says: Vuex is a state management pattern + library for Vue.js applications. It serves as a centralized store for all the components in an application, with rules ensuring that the state can only be mutated in a predictable fashion.
If you want to share the logic in different components, then mixins is want you’re looking for. Mixins are a flexible way to distribute reusable functionalities for Vue components. A mixin object can contain any component options. When a component uses a mixin, all options in the mixin will be “mixed” into the component’s own options.
You can also mix both and access the centralized Vuex store from within the mixin.