Vue.js & Composition API (50 Qs)•Part 1: Basic & Foundational Concepts (Junior / Entry-Level)
How do `computed()` and `watch()` work in Vue 3?
junior LevelSignalsVue & Nuxt
In Simple Words:
computed(() => ...):- Derives a new reactive value from existing state.
- Cached: Recomputes only when its reactive dependencies change.
- Read-only by default (can define custom getter/setter).
watch(source, callback):- Executes a side-effect (making an API call, logging, setting local storage) in response to state changes.
- Lazy by default: Does not run until the watched state actually changes (unless
{ immediate: true }is set). - Provides both the
newValueandoldValue.