[Vuejs]-Passing an object to a component

0👍

One method would be to send the data back up through a custom event.

in the child:

export default {
  props: ['item'],
  data() {
    return {
      myitem: ''
    };
  },
  methods: {
    childChanged () {
      // childChanged is your method of updating this items values
      this.$emit('mymethod', this.myitem); // emit to parent
    }
  },
  mounted(){
     this.myitem = this.item; // assign props to self
  }
}

In the parent capture the event being emitted

<child-component @mymethod="updateItems"></child-component>

and then in methods:

  methods: {
    updateItems(data){
      this.items[selected] = data;
    }
  }

Leave a comment