0👍
The placement for the listener attribute should be on the child component:
<star-with-label :label="value" :property="property" @sent-rating-in-parent="onClickChild">
To create the object: { 'property1': 'value1', 'property2': 'value2' ... }
The child can emit the property
and value
, and you’d have to make the object in the parent.
Maybe something like this:
/* child */
setCurrentSelectedRating: function(rating) {
this.$emit({ property: this.property, rating: this.rating }); // { property: bk_goodwill, rating: 4.76 }
}
/* parent */
data() {
propertyRatings: {}
},
methods: {
onClickChild({ property, rating }) {
this.propertyRating[property] = rating
console.log(this.propertyRating) // { bk_goodwill: 4.76 }
}
Source:stackexchange.com