[Vuejs]-The problem of data transfer between two child components

2👍

You can wrap title and body in an object

addPost() {
      const post = {
        title: this.createTitle,
        body: this.createBody
      }
      eventEmitter.$emit('postAdd', post)
    }

and then listen as normal

created(){
  eventEmitter.$on('postAdd', (post) => {
    console.log(post)
    // do whatever you want
  })
}
👤ittus

1👍

I have not worked on vue js but agreed with @ittus answer. You can make an object consisting of your required data which you want to share across the component and pass it as an event data.

Leave a comment