3

I'm working on a large project built with vue. We are using vuex as the state management system but their are some components where I don't need to access their data anywhere else. So, Is it right to store this data in the component data or stick with the convention and store it in a vuex module. Thanks in advance.

2 Answers2

4

You need to use Vuex store if the data must be accessible by multiple (independent) components. There are several reasons why you shouldn't store everything in Vuex store.

First things first complexity! If you are building a complex Vuex store you can not use effectively as your project grows.

On the other hand if you're filling your store with unnecessary states, all the states will executed in the first load in the initial JS and the more data will increase the payloads and that occurs longer load of the webapp.

So the best thing what you can do it is keep your local states locally until is it possible, und use Vuex when the communication of independent components is needed.

robertkovacs
  • 435
  • 3
  • 14
1

You can keep data with in your components. You can convert your non data sharing components to Functional Components link here.

Vue process functional components faster than normal one. By converting to functional one you will gain some performance boost.

It is totally fine to keep data with in the components if you don't need to access it globally.

When you create more than one Function Components, You must create keys for them too. You can find the whole conversation here. I gave all the details there with code samples as well.

ENJOY CODING....