Home / Function/ defineComputed() — vue Function Reference

defineComputed() — vue Function Reference

Architecture documentation for the defineComputed() function in state.ts from the vue codebase.

Function typescript CoreRuntime Instance calls 2 called by 2

Entity Profile

Dependency Diagram

graph TD
  d78d0fa2_2aba_d914_c67d_4cb1b5a75d62["defineComputed()"]
  910d3a96_5984_cf85_40a3_47933bd75818["state.ts"]
  d78d0fa2_2aba_d914_c67d_4cb1b5a75d62 -->|defined in| 910d3a96_5984_cf85_40a3_47933bd75818
  bbde495f_48f3_a910_410f_28718d2c8ee1["initComputed()"]
  bbde495f_48f3_a910_410f_28718d2c8ee1 -->|calls| d78d0fa2_2aba_d914_c67d_4cb1b5a75d62
  7b0a7d03_cfef_5efb_b868_2bd41b0196d7["initComputed()"]
  7b0a7d03_cfef_5efb_b868_2bd41b0196d7 -->|calls| d78d0fa2_2aba_d914_c67d_4cb1b5a75d62
  94a80262_5bce_62f3_1f0f_6faf27d0f66d["createComputedGetter()"]
  d78d0fa2_2aba_d914_c67d_4cb1b5a75d62 -->|calls| 94a80262_5bce_62f3_1f0f_6faf27d0f66d
  5db40f3a_eaee_7312_3254_f6f5bf2f7eaf["createGetterInvoker()"]
  d78d0fa2_2aba_d914_c67d_4cb1b5a75d62 -->|calls| 5db40f3a_eaee_7312_3254_f6f5bf2f7eaf
  style d78d0fa2_2aba_d914_c67d_4cb1b5a75d62 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/instance/state.ts lines 226–254

export function defineComputed(
  target: any,
  key: string,
  userDef: Record<string, any> | (() => any)
) {
  const shouldCache = !isServerRendering()
  if (isFunction(userDef)) {
    sharedPropertyDefinition.get = shouldCache
      ? createComputedGetter(key)
      : createGetterInvoker(userDef)
    sharedPropertyDefinition.set = noop
  } else {
    sharedPropertyDefinition.get = userDef.get
      ? shouldCache && userDef.cache !== false
        ? createComputedGetter(key)
        : createGetterInvoker(userDef.get)
      : noop
    sharedPropertyDefinition.set = userDef.set || noop
  }
  if (__DEV__ && sharedPropertyDefinition.set === noop) {
    sharedPropertyDefinition.set = function () {
      warn(
        `Computed property "${key}" was assigned to but it has no setter.`,
        this
      )
    }
  }
  Object.defineProperty(target, key, sharedPropertyDefinition)
}

Domain

Subdomains

Frequently Asked Questions

What does defineComputed() do?
defineComputed() is a function in the vue codebase, defined in src/core/instance/state.ts.
Where is defineComputed() defined?
defineComputed() is defined in src/core/instance/state.ts at line 226.
What does defineComputed() call?
defineComputed() calls 2 function(s): createComputedGetter, createGetterInvoker.
What calls defineComputed()?
defineComputed() is called by 2 function(s): initComputed, initComputed.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free