Recall & Review
beginner
What is a computed property in Vue?
A computed property is a special reactive value that automatically updates when its dependencies change. It is used to calculate values based on other data in a Vue component.
Click to reveal answer
intermediate
How does a computed property with a getter and setter work in Vue?
It has two parts: a getter to return a value based on reactive data, and a setter to update reactive data when the computed property is changed.
Click to reveal answer
intermediate
Why use a setter in a computed property?
A setter lets you react to changes when someone modifies the computed property, allowing you to update the underlying data accordingly.
Click to reveal answer
beginner
Show a simple example of a computed property with getter and setter in Vue.
Example:
const fullName = computed({
get() { return firstName.value + ' ' + lastName.value },
set(value) {
const parts = value.split(' ')
firstName.value = parts[0]
lastName.value = parts.slice(1).join(' ') || ''
}
})Click to reveal answer
beginner
What happens if you only provide a getter in a computed property?
The computed property becomes read-only. You cannot assign a new value to it because there is no setter to handle changes.
Click to reveal answer
What does the setter in a Vue computed property do?
✗ Incorrect
The setter updates the reactive data when you assign a new value to the computed property.
If a computed property has only a getter, what is true?
✗ Incorrect
Without a setter, the computed property is read-only and cannot be assigned new values.
Which Vue API is used to create a computed property with getter and setter?
✗ Incorrect
The computed() function creates computed properties with optional getter and setter.
What is a common use case for a computed property with a setter?
✗ Incorrect
Setters let you update multiple reactive values when the computed property changes, like splitting a full name into first and last names.
In Vue, what happens when dependencies of a computed property change?
✗ Incorrect
Computed properties automatically recalculate when their reactive dependencies change.
Explain how a computed property with getter and setter works in Vue and why it is useful.
Think about how you can both read and write a computed value.
You got /3 concepts.
Describe a real-life example where a computed property with getter and setter would help manage data in a Vue component.
Imagine editing a full name input that updates separate fields.
You got /3 concepts.