opendev
opendev

Reputation: 29

Vue3:How to pass updated props to child component

I'm trying to figure out how to pass updated props to child component. For example,

// parent component
// temp is an reactive object
<Child :temp="temp">

and in Child component,when temp gets modified, the temp props isn't changed.

I'm using script-setup in vue3.

Can you please help me with this issue?

Upvotes: 0

Views: 73

Answers (2)

Pardon_me
Pardon_me

Reputation: 13

To see the change, set up a watcher in the child component like this.

watch(() => props.temp, (newValue, oldValue) => {
    console.log(props.temp);
});

If the variable "temp" changes in the parent component, this watcher should trigger.

Upvotes: 0

nocrash9000
nocrash9000

Reputation: 401

Are you modifying temp in child component? You should avoid manipulation of props.

Otherwise: Are you assigning temp to another variable? It's easy to lose reactivity when doing so, I have learned.

If you provide a little more context your question might get more helpful answers.

Upvotes: 0

Related Questions