0

I have a projects view that contains 3 components, <project-item>, <project-list> and <project-view>. All of these components need to be aware of the selected projects.

  • <project-item> holds the state for a particular project. This component has a property called selected which determines if the project is selected or not.
  • <project-list> houses one or more project-items and has a computed property which checks the children are of type <project-item> and which items are selected.
  • <project-view> is the general view which just contains navigation and logic associated UAC.

The hierarchy looks like this...

<project-view>
    <project-list>
        <project-item selected></project-item>
    </project-list>
</project-view>

What would be the best way of sharing that state as i feel vuex is the wrong choice here as it's not global state.

I also have tried to use a computed property on the <project-view> component to get the selected items on the <project-list> component but it throws errors despite existing and being in scope.

nblackburn
  • 268
  • 2
  • 14

2 Answers2

2

If you think that Vuex is overkill, then check my answer here - pretty same topic

VueJS access child component's data from parent

Community
  • 1
  • 1
Belmin Bedak
  • 9,011
  • 2
  • 40
  • 44
1

Vuex is your answer. https://vuex.vuejs.org/en/intro.html

This is the solution for the sharing of states.

You will create the store, connect your states with store and use actions/mutations to work with them.

It will give you great foundation for state sharing which, if you will need to, you will easily scale up.

Good luck!

Marek Urbanowicz
  • 12,659
  • 16
  • 62
  • 87
  • I always have seen Vuex as a global state not one between a couple of components which is why i don't think it's right to use this method. – nblackburn Feb 06 '17 at 14:06
  • 1
    It is right. Always when developing stuff, use scalable solutions. You never know how your project will grow up. Introduction time of Vuex is like 20-30 minutes, it is not big job. – Marek Urbanowicz Feb 06 '17 at 14:08
  • I already use it but only on stuff i consider the entire application needs to be aware of but it's a fair point, i can't see why i can't use it on a smaller scale too. – nblackburn Feb 06 '17 at 14:10