← Vue.js Foundations
5 / 25
Lesson 5 — computed
Values calculated from other values
computed(() => …) creates a value that is calculated from other reactive values and recalculated automatically when they change. Vue caches it, so it is only recomputed when an input actually changed. In the script you read refs with .value; the template unwraps them for you.
const price = ref(10)
const withTax = computed(() => price.value * 1.2)
Why it matters: totals, counts and formatted text stay correct without manual updating.
Want it another way?
Task
Make double a computed. The preview should show "2 doubled is 4", and after +1 "3 doubled is 6".
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.