Skip to content
Discussion options

You must be logged in to vote

You are declaring x-data in two sibling elements. Changing myVar on the first won't affect the second. Moving x-data to a parent element fixes it.

The $persist() plugin will automatically take care of stringifying and parsing its value to/from JSON. You can also remove both x-effect attributes.

<div x-data="{ myVar: $persist(false) }">
  <button
    x-text="myVar"
    @click="myVar = !myVar"
  >
  </button>

  <div x-show="myVar">
      Show when myVar = true
  </div>
</div>

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@SimoTod
Comment options

SimoTod Jul 23, 2021
Collaborator

@SimoTod
Comment options

SimoTod Jul 23, 2021
Collaborator

@robdekort
Comment options

@SimoTod
Comment options

SimoTod Jul 23, 2021
Collaborator

@robdekort
Comment options

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