Question 96 MCQ · 2.0 marks
On every component render
When one of its reactive dependencies changes
At fixed time intervals
Only when explicitly called
Published solution
In Vue.js, a **computed property** is cached based on its reactive dependencies (the reactive data properties inside the Vue instance that it reads during execution).
**1. How Computed Caching Works:**
When a computed property is first evaluated, Vue tracks every reactive state variable accessed inside its getter function. As long as none of those tracked dependencies change, subsequent accesses to the computed property immediately return the previously cached result without re-running the function.
**2. Trigger for Re-evaluation:**
Vue only marks the cached value as stale and re-evaluates the computed property when at least one of its reactive dependencies is mutated.
**Answer: When one of its reactive dependencies changes.**
A: **Incorrect:** Regular `methods` re-run on every component render when called in a template, whereas `computed` properties are cached and do not re-run on every render unless a dependency changes.
B: **Correct:** Vue caches computed properties and only re-evaluates them when one of their tracked reactive dependencies changes.
C: **Incorrect:** Vue reactivity is dependency-driven, not polling- or timer-based.
D: **Incorrect:** Computed properties are accessed like normal properties and automatically update reactively; they are not manually invoked like functions.