[Vuejs]-Changing state from component to component

0👍

The solution to this depends on how distant your components are. Do they share the same parent? Then they can communicate through event emitting and props:

parent component
    calendar > $emit('setDate', date) // emits event with the date to parent 
    sidebar  > :selected-date="date"  // receives date via prop from the parent

If the components share no parent or are really far from each other (the common parent is 2 or more components away) some kind of state management like Vuex (https://vuex.vuejs.org/guide/) makes life easier.

This article explains it quite well: https://www.smashingmagazine.com/2020/01/data-components-vue-js/

Leave a comment