An easy fix to this example situation would be to add a key on the button with the value of counter
key
counter
<button :key="counter" @click="increase">
Can you explain why adding a key solves the problem?
Vue uses keys for deterministic re-evaluation. It's use case is typically for loops, but a key can be used on any component/element. When a key changes, that forces Vue to do a re-evaluation.
Nope, additing key on the button would not make any difference
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
An easy fix to this example situation would be to add a
key
on the button with the value ofcounter
Can you explain why adding a key solves the problem?
Vue uses keys for deterministic re-evaluation. It's use case is typically for loops, but a key can be used on any component/element. When a key changes, that forces Vue to do a re-evaluation.
Nope, additing key on the button would not make any difference