DEV Community

Discussion on: Vue: When a computed property can be the wrong tool

Collapse
hawkeye64 profile image
Jeff Galbraith

An easy fix to this example situation would be to add a key on the button with the value of counter

<button :key="counter" @click="increase">
Enter fullscreen mode Exit fullscreen mode
Collapse
dajpes profile image
dajpes

Can you explain why adding a key solves the problem?

Collapse
hawkeye64 profile image
Jeff Galbraith

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.