While developing vuejs project, I often meet a situation like the following:
Here "this" is the vue component.
I would love to refactor this code to look it very nice.
Please share your idea with me.
Thank you.
const newReportPart = {
id: this.id,
title: this.title,
description: this.description,
product_id: this.product_id,
product_title: this.product_title,
rate: this.rate,
saved: this.saved,
attachments: this.attachments,
};
this.$emit('submitReportPart', this.index, newReportPart);
Top comments (4)
what about this?
are there other props you on this that should not get added o the event? maybe you want to checkout
underscore
js with itspick
oromit
methods.I see what you are meaning. but 'this' is Vue Component, and I want to pass only those parameters into newReportPart.
So I will take a look at pick or omit methods.
Thank you.
You can use
this.$data
I guess you should clone
$data
before emit itthis.$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.
And it works well.
Thank you for all your commenting here. :heart