Skip to content
Discussion options

You must be logged in to vote

The closest thing to your initial example is probably

<div x-data="{ value: 20, diff: 5, add: false }">
    <button @click="add = ! add" x-text="value + (add ? diff : 0)"></button>  
</div>

In a nutshell, you need a control flag, you can't use the variable holding the value as a boolean.

If you need to update value, instead of just showing it, you can use something like

<div x-data="{ value: 20, diff: 5, added: false }">
    <button @click="value +=  (added ? (diff * -1) : diff); added = ! added" x-text="value"></button>  
</div> 

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@fredbouin
Comment options

@SimoTod
Comment options

SimoTod Feb 19, 2022
Collaborator

@fredbouin
Comment options

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