Reputation: 716
I would like to pass data to child component but do not want to bind it when the data changes in the parent
<parent :val="myval">
<child :initialval="val"></child>
</parent>
This code binds my initial value to myval
, I just want it to be passed first time and do not want initialval
to be reactive to changes of my val.
Can I do it without setting a local variable in mounted()
function of child
component?
Upvotes: 2
Views: 1402
Reputation: 43899
You want to initialize the component's data from a prop:
<parent :val="myval">
<child :initialval="val"></child>
</parent>
and in the child:
data() {
return {
value: initialval
};
}
then use the component's data item (value
in my example here) instead of the prop for whatever you're doing in the component.
Upvotes: 3
Reputation: 2138
you can use the v-once attribute
<child :initialval="val" v-once></child>
Upvotes: 0