-
I was hoping that changes to parent data values could cascade to modified child values: <div x-data="{age: 2}">
<input type="number" x-model="age">
<div x-text="'Age: ' + age"></div>
<div x-data="{age: age * 2}" x-text="'Double: ' + age"></div>
</div> But that throws:
Is there a way to accomplish something similar to this? Obviously you could change Similar conversations:
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
x-data is not reactive. it gets evaluated once at init. When you define a property, that is just a value from that point. To define it in data as a reactive value you need to use a function (or in your case you probably want to use a getter) so the value gets evaluated when used and stay reactive: <div x-data="{age: 2}">
<input type="number" x-model="age">
<div x-text="'Age: ' + age"></div>
<div x-data="{get age() { return age * 2 } }" x-text="'Double: ' + age"></div>
</div> |
Beta Was this translation helpful? Give feedback.
x-data is not reactive. it gets evaluated once at init. When you define a property, that is just a value from that point. To define it in data as a reactive value you need to use a function (or in your case you probably want to use a getter) so the value gets evaluated when used and stay reactive: