Skip to content

Reactive parent x-data in child x-data #4490

Answered by SimoTod
jimafisk asked this question in 1. Help
Discussion options

You must be logged in to vote

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>

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@jimafisk
Comment options

@ekwoka
Comment options

@jimafisk
Comment options

@ekwoka
Comment options

@jimafisk
Comment options

Answer selected by jimafisk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants