[Vuejs]-How to get same value in two components using vuejs $emit

0👍

Yes this is possible. It is a two-way binding and is kind of the basis of SPAs. In your parent component, pass the variable as a prop down to the child, then $emit up your variable.

Your component inside your parent.

   <NewWorld :yourpropname="this.yourvar" @yourEmitterName="handleEmit($event)" />

A method for handling the emit in the parent

    handleEmit(data) {
      this.yourvar = data;
    },

Inside your child, set a variable = to your prop, then emit that up. The var will be the same in both componenets

You can emit it on any change with something like

            @update:model-value="$emit('yourEmitterName', this.yourVar)"

Leave a comment