Vue · Senior · Question 51 of 75
What does the previous argument of a computed getter (Vue 3.4+) allow?
const max = computed((previous) => {
const next = Math.max(...values.value)
return previous !== undefined && previous > next ? previous : next
})- ✓Correct answer: Reading the previously computed value, e.g. to keep a stable result
- 2Undoing the last state change
- 3Computing values asynchronously
Explanation
Returning the old object when nothing meaningful changed keeps references stable for downstream computeds and watchers.