Rebbeca
Rebbeca

Reputation: 1987

Is it bad to use a watch in a child component?

In my project, I need to know the changes in the child components in real time from the parent component.

So I'm going to use watch in a child component to emit event to the parent component whenever the data in the child component changes.

Is this a bad way? I'm afraid there's an unnecessary overload in this flow.

If you have a better way, please recommend it.

Upvotes: 1

Views: 810

Answers (1)

Daniel Elkington
Daniel Elkington

Reputation: 3647

There's nothing wrong with this approach. Vue is very efficient in the way it detects changes, and there shouldn't be an unnecessary overload, unless you watch more than you need to. You shouldn't notice any performance issues unless you have a huge object graph (eg thousands of objects being watched).

Make sure you only watch the properties that require change detection, and only use deep:true if you really need to.

Upvotes: 1

Related Questions