Home / Function/ initProps() — vue Function Reference

initProps() — vue Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  a592e65e_63b6_f3cc_cc80_030328fd88d5["initProps()"]
  d6eecf16_0b33_9978_9ebb_d8829be93c79["initProps()"]
  d6eecf16_0b33_9978_9ebb_d8829be93c79 -->|calls| a592e65e_63b6_f3cc_cc80_030328fd88d5
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289["initState()"]
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289 -->|calls| a592e65e_63b6_f3cc_cc80_030328fd88d5
  65e1e423_bb6b_4902_ff2a_5a19cc670a5f["toggleObserving()"]
  a592e65e_63b6_f3cc_cc80_030328fd88d5 -->|calls| 65e1e423_bb6b_4902_ff2a_5a19cc670a5f
  558ee358_0776_b0dd_fc5b_6c8f87e1a04e["defineReactive()"]
  a592e65e_63b6_f3cc_cc80_030328fd88d5 -->|calls| 558ee358_0776_b0dd_fc5b_6c8f87e1a04e
  b28f2cc5_e9df_82f7_d7e9_a1e5617cf102["proxy()"]
  a592e65e_63b6_f3cc_cc80_030328fd88d5 -->|calls| b28f2cc5_e9df_82f7_d7e9_a1e5617cf102
  style a592e65e_63b6_f3cc_cc80_030328fd88d5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/instance/state.ts lines 72–126

function initProps(vm: Component, propsOptions: Object) {
  const propsData = vm.$options.propsData || {}
  const props = (vm._props = shallowReactive({}))
  // cache prop keys so that future props updates can iterate using Array
  // instead of dynamic object key enumeration.
  const keys: string[] = (vm.$options._propKeys = [])
  const isRoot = !vm.$parent
  // root instance props should be converted
  if (!isRoot) {
    toggleObserving(false)
  }
  for (const key in propsOptions) {
    keys.push(key)
    const value = validateProp(key, propsOptions, propsData, vm)
    /* istanbul ignore else */
    if (__DEV__) {
      const hyphenatedKey = hyphenate(key)
      if (
        isReservedAttribute(hyphenatedKey) ||
        config.isReservedAttr(hyphenatedKey)
      ) {
        warn(
          `"${hyphenatedKey}" is a reserved attribute and cannot be used as component prop.`,
          vm
        )
      }
      defineReactive(
        props,
        key,
        value,
        () => {
          if (!isRoot && !isUpdatingChildComponent) {
            warn(
              `Avoid mutating a prop directly since the value will be ` +
                `overwritten whenever the parent component re-renders. ` +
                `Instead, use a data or computed property based on the prop's ` +
                `value. Prop being mutated: "${key}"`,
              vm
            )
          }
        },
        true /* shallow */
      )
    } else {
      defineReactive(props, key, value, undefined, true /* shallow */)
    }
    // static props are already proxied on the component's prototype
    // during Vue.extend(). We only need to proxy props defined at
    // instantiation here.
    if (!(key in vm)) {
      proxy(vm, `_props`, key)
    }
  }
  toggleObserving(true)
}

Domain

Subdomains

Frequently Asked Questions

What does initProps() do?
initProps() is a function in the vue codebase.
What does initProps() call?
initProps() calls 3 function(s): defineReactive, proxy, toggleObserving.
What calls initProps()?
initProps() is called by 2 function(s): initProps, initState.

Analyze Your Own Codebase

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

Try Supermodel Free