Communicating Between Two Components
-
I have two
.vue
files:header.vue
anddrawer.vue
.header.vue
contains a button that is supposed to toggle open or shut the drawer (it does so by toggling a boolean value to true or false).drawer.vue
has thedata
that needs to be toggled when the button is clicked (i.e., it contains the boolean value).How can I get the two files to communicate with one another without having to combine the contents of the two file into a single
.vue
. file? -
@moshemo put the variable drawerOpen in Vuex then in both components you can use vue computed getter and setter:
https://vuejs.org/v2/guide/computed.html#Computed-Setter
The code for those getters you can even put in the mixins and import it in both components:
https://vuejs.org/v2/guide/mixins.html