DEV Community


Discussion on: How can I refactor this code snippet?

donsalvador profile image

You can use this.$data

   this.$emit('submitReportPart', this.index, this.$data);

I guess you should clone $data before emit it

yeahch profile image
ch Author

this.$data is a object, and is a reference.
So emitting with this.$data incurs some reference error while running.
In order to pass value as a clone, I refactored it like the following.

const reportPartData = { ...this.$data };
this.$emit('submitReportPart', this.index, reportPartData);

And it works well.
Thank you for all your commenting here. :heart