tezvyn:

Fundamental difference between Vue computed and watcher with examples

Source: vuejs.orgintermediate

Tests derived state vs side effects in Vue reactivity. Computed returns cached derived value; watch executes callback on mutation. Example: computed filters list; watch fetches data when ID changes. Red flag: watch for template state or computed for async.

Tests whether you understand Vue reactivity enough to pick the right primitive. A strong answer states that computed properties are synchronous, pure getters that cache results based on reactive dependencies and are meant for deriving state. Watchers are for imperative side effects, running a callback when a reactive source changes. Use computed to filter a list for display because it is lazy and memoized. Use watch to trigger an API call when a route parameter changes.

Read the original → vuejs.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Fundamental difference between Vue computed and watcher with examples · Tezvyn