Home / Function/ initData() — vue Function Reference

initData() — vue Function Reference

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

Function typescript CoreRuntime Instance calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  71dd8c80_4600_3a78_a4ac_26befd4658cc["initData()"]
  910d3a96_5984_cf85_40a3_47933bd75818["state.ts"]
  71dd8c80_4600_3a78_a4ac_26befd4658cc -->|defined in| 910d3a96_5984_cf85_40a3_47933bd75818
  ceeb400a_fb7f_c638_1feb_8311db20c105["initState()"]
  ceeb400a_fb7f_c638_1feb_8311db20c105 -->|calls| 71dd8c80_4600_3a78_a4ac_26befd4658cc
  ce80ecf6_59b6_ce14_f480_11914f02b5b1["getData()"]
  71dd8c80_4600_3a78_a4ac_26befd4658cc -->|calls| ce80ecf6_59b6_ce14_f480_11914f02b5b1
  cedf6e5d_ac48_bf6f_0fc6_d75bd1082b6e["proxy()"]
  71dd8c80_4600_3a78_a4ac_26befd4658cc -->|calls| cedf6e5d_ac48_bf6f_0fc6_d75bd1082b6e
  c50e49cd_c223_e73e_c96d_1c8391fde3c1["observe()"]
  71dd8c80_4600_3a78_a4ac_26befd4658cc -->|calls| c50e49cd_c223_e73e_c96d_1c8391fde3c1
  style 71dd8c80_4600_3a78_a4ac_26befd4658cc fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/core/instance/state.ts lines 128–166

function initData(vm: Component) {
  let data: any = vm.$options.data
  data = vm._data = isFunction(data) ? getData(data, vm) : data || {}
  if (!isPlainObject(data)) {
    data = {}
    __DEV__ &&
      warn(
        'data functions should return an object:\n' +
          'https://v2.vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
        vm
      )
  }
  // proxy data on instance
  const keys = Object.keys(data)
  const props = vm.$options.props
  const methods = vm.$options.methods
  let i = keys.length
  while (i--) {
    const key = keys[i]
    if (__DEV__) {
      if (methods && hasOwn(methods, key)) {
        warn(`Method "${key}" has already been defined as a data property.`, vm)
      }
    }
    if (props && hasOwn(props, key)) {
      __DEV__ &&
        warn(
          `The data property "${key}" is already declared as a prop. ` +
            `Use prop default value instead.`,
          vm
        )
    } else if (!isReserved(key)) {
      proxy(vm, `_data`, key)
    }
  }
  // observe data
  const ob = observe(data)
  ob && ob.vmCount++
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does initData() do?
initData() is a function in the vue codebase, defined in src/core/instance/state.ts.
Where is initData() defined?
initData() is defined in src/core/instance/state.ts at line 128.
What does initData() call?
initData() calls 3 function(s): getData, observe, proxy.
What calls initData()?
initData() is called by 1 function(s): initState.

Analyze Your Own Codebase

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

Try Supermodel Free