0👍
The way I would recommend doing this (for most cases) is to use vuex.
These are the files I would use
- vuex (store, actions, mutators, getters)
- apiHandler (a utility function making the actual call)
- component 1
- component 2
After some action on component 1, a vuex action is triggered. Inside the vuex action the appropriate apiHandler function is invoked. Inside the vuex action the response is handled with a then()
, which pushes the response into the vuex mutator. This mutation will update the getter which will update any component that is listening to the change in state.
It’s a bit more complex than having the components talk directly, but it makes the architecture scalable.
Source:stackexchange.com