'Provide/inject or Vuex?
I have a list of cars. Each item of that list has all the information about some of the cars. Also each item is a parent component to many other components - image, price, characteristics, etc - all that info is in separate components. The information about all those cars is stored in Vuex. Now I think of a better way to pass that information to each of the list items.
- Pass all the neccessary data about another car to the parent component. And then provide it to the child components.
- Each child comonent get the neccessary information from the Vuex directly.
Solution 1:[1]
Provide-inject is mainly used to pass data to nested components.
Vuex on the other hand, keeps the app state shared.
You need to ask yourself whether the data you need in your component is coming from a parent-parent component or the data is used in many components in different parts of the app. If you need the first, then go with the provide-inject, otherwise, pick Vuex.
Both approaches are prone to be badly implemented and potentially impact negatively on your app development and maintainability, so be very careful and learn the basics in-depth ;)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pablo Ezequiel Leone |
