1

I have 2 non parent/child components. I'd like to run a function on component A by clicking a button on component B. I know that the eventbus is a solution but because I am already using Vuex I would like to do it the Vuex way but could not find an example on the internet.

MK01111000
  • 770
  • 2
  • 9
  • 16

1 Answers1

1

Have component A mutate some state that component B is watching. When component B see's a change to that state, run your function.

The mutation could be as simple as flipping a boolean or incrementing a number. Anything to trigger the watch in the other component.

Here is how to setup the watch: https://stackoverflow.com/a/44347195/1409310

Joseph Connolly
  • 891
  • 11
  • 21