Home / Function/ initComputed() — vue Function Reference

initComputed() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  0c237bbb_9732_89a2_cbb9_7c182a36d1d8["initComputed()"]
  513e4cf1_6313_4e41_3156_8a9840fbfa91["initComputed()"]
  513e4cf1_6313_4e41_3156_8a9840fbfa91 -->|calls| 0c237bbb_9732_89a2_cbb9_7c182a36d1d8
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289["initState()"]
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289 -->|calls| 0c237bbb_9732_89a2_cbb9_7c182a36d1d8
  cba9a7a5_cb68_c483_2155_95fbf45613ad["defineComputed()"]
  0c237bbb_9732_89a2_cbb9_7c182a36d1d8 -->|calls| cba9a7a5_cb68_c483_2155_95fbf45613ad
  style 0c237bbb_9732_89a2_cbb9_7c182a36d1d8 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/instance/state.ts lines 183–224

function initComputed(vm: Component, computed: Object) {
  // $flow-disable-line
  const watchers = (vm._computedWatchers = Object.create(null))
  // computed properties are just getters during SSR
  const isSSR = isServerRendering()

  for (const key in computed) {
    const userDef = computed[key]
    const getter = isFunction(userDef) ? userDef : userDef.get
    if (__DEV__ && getter == null) {
      warn(`Getter is missing for computed property "${key}".`, vm)
    }

    if (!isSSR) {
      // create internal watcher for the computed property.
      watchers[key] = new Watcher(
        vm,
        getter || noop,
        noop,
        computedWatcherOptions
      )
    }

    // component-defined computed properties are already defined on the
    // component prototype. We only need to define computed properties defined
    // at instantiation here.
    if (!(key in vm)) {
      defineComputed(vm, key, userDef)
    } else if (__DEV__) {
      if (key in vm.$data) {
        warn(`The computed property "${key}" is already defined in data.`, vm)
      } else if (vm.$options.props && key in vm.$options.props) {
        warn(`The computed property "${key}" is already defined as a prop.`, vm)
      } else if (vm.$options.methods && key in vm.$options.methods) {
        warn(
          `The computed property "${key}" is already defined as a method.`,
          vm
        )
      }
    }
  }
}

Domain

Subdomains

Frequently Asked Questions

What does initComputed() do?
initComputed() is a function in the vue codebase.
What does initComputed() call?
initComputed() calls 1 function(s): defineComputed.
What calls initComputed()?
initComputed() is called by 2 function(s): initComputed, initState.

Analyze Your Own Codebase

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

Try Supermodel Free