computed() Create a Computed Property

Last updated: 2026-10-22

computed() Create a Computed Property

computed() derives a value from other reactive state and caches it: it re-evaluates only when a dependency changes.

GroupReactivity: Core
KindAPI
ScopeComponent
Vue Version3.0+
SSR SupportYes

📝 Syntax

const doubled = computed(() => count.value * 2)

// writable computed
const full = computed({
  get: () => first.value + " " + last.value,
  set: (v) => { [first.value, last.value] = v.split(" ") }
})

⚙️ Arguments

getterA getter function (or an object with get/set) reading other reactive state

Returns:A readonly (or writable) ComputedRef object

▶ Example

Edit the code below and see the live result:

Output:

Shows 'Total: 20' by default; editing either input recalculates the total instantly.

💡 Key Points

💡 Tip Cached: reused across the page but computed once, unlike a method call which re-runs on every render.
⚠️ Warning Do not put side effects (requests, mutating other state) inside a computed getter — that is watch's job.
ℹ️ Note It only tracks real reactive sources: with no reactive dependency, the value never updates.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Should I use computed or a method?
A Derived reactive values reused in several places → computed (cached). Parameterized calls or per-invocation work → a plain function.
Q Can I assign to a computed?
A It is readonly by default and assigning warns. Provide a { get, set } object to make it writable.
Q Can a computed be asynchronous?
A No — computed must return synchronously; use watch plus a ref for async derivations.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏