All jobs / Frontend / web developer / Vue

Frontend / web developer interview question · 1–3 years

In Vue, when do you use a computed property and when a watcher?

The strongest answer

computed for values derived from other state — cached until a dependency changes; watch for side effects such as a request or saving a draft. Derived state kept in sync by a watcher is a smell

Why it works

Exactly — derive with computed, react with watch. A watcher that only copies state into other state is a computed waiting to be written.

What a good answer covers

Answers that fall short

Who gets asked this

More Vue questions