Home / Function/ initSetup() — vue Function Reference

initSetup() — vue Function Reference

Architecture documentation for the initSetup() function in apiSetup.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6["initSetup()"]
  4ad51b1f_61ec_31ba_dbb7_667d6a0a8c85["apiSetup.ts"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|defined in| 4ad51b1f_61ec_31ba_dbb7_667d6a0a8c85
  90e994f6_eac7_d182_0e97_d5a116aca32a["createSetupContext()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| 90e994f6_eac7_d182_0e97_d5a116aca32a
  d1e6589c_ca32_48f9_4b75_7ccf5ae438ec["setCurrentInstance()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| d1e6589c_ca32_48f9_4b75_7ccf5ae438ec
  46145e02_0be2_a179_3c66_d786e8df82f3["pushTarget()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| 46145e02_0be2_a179_3c66_d786e8df82f3
  94784772_3664_4cb1_fcad_0275dfc601d0["shallowReactive()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| 94784772_3664_4cb1_fcad_0275dfc601d0
  f641f94c_5096_9084_3285_10f3d148c139["popTarget()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| f641f94c_5096_9084_3285_10f3d148c139
  13ab3a27_e98e_1f11_fa3d_2ae15be5c797["isFunction()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| 13ab3a27_e98e_1f11_fa3d_2ae15be5c797
  b9b5088c_fb08_6800_f248_ef1b18619844["isObject()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| b9b5088c_fb08_6800_f248_ef1b18619844
  f813e3f0_a8fa_7690_027d_8675e5e0c8e0["proxyWithRefUnwrap()"]
  68e41397_5a92_5b2b_c03f_8a2d186bd3a6 -->|calls| f813e3f0_a8fa_7690_027d_8675e5e0c8e0
  style 68e41397_5a92_5b2b_c03f_8a2d186bd3a6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/v3/apiSetup.ts lines 28–85

export function initSetup(vm: Component) {
  const options = vm.$options
  const setup = options.setup
  if (setup) {
    const ctx = (vm._setupContext = createSetupContext(vm))

    setCurrentInstance(vm)
    pushTarget()
    const setupResult = invokeWithErrorHandling(
      setup,
      null,
      [vm._props || shallowReactive({}), ctx],
      vm,
      `setup`
    )
    popTarget()
    setCurrentInstance()

    if (isFunction(setupResult)) {
      // render function
      // @ts-ignore
      options.render = setupResult
    } else if (isObject(setupResult)) {
      // bindings
      if (__DEV__ && setupResult instanceof VNode) {
        warn(
          `setup() should not return VNodes directly - ` +
            `return a render function instead.`
        )
      }
      vm._setupState = setupResult
      // __sfc indicates compiled bindings from <script setup>
      if (!setupResult.__sfc) {
        for (const key in setupResult) {
          if (!isReserved(key)) {
            proxyWithRefUnwrap(vm, setupResult, key)
          } else if (__DEV__) {
            warn(`Avoid using variables that start with _ or $ in setup().`)
          }
        }
      } else {
        // exposed for compiled render fn
        const proxy = (vm._setupProxy = {})
        for (const key in setupResult) {
          if (key !== '__sfc') {
            proxyWithRefUnwrap(proxy, setupResult, key)
          }
        }
      }
    } else if (__DEV__ && setupResult !== undefined) {
      warn(
        `setup() should return an object. Received: ${
          setupResult === null ? 'null' : typeof setupResult
        }`
      )
    }
  }
}

Domain

Subdomains

Defined In

Frequently Asked Questions

What does initSetup() do?
initSetup() is a function in the vue codebase, defined in src/v3/apiSetup.ts.
Where is initSetup() defined?
initSetup() is defined in src/v3/apiSetup.ts at line 28.
What does initSetup() call?
initSetup() calls 8 function(s): createSetupContext, isFunction, isObject, popTarget, proxyWithRefUnwrap, pushTarget, setCurrentInstance, shallowReactive.

Analyze Your Own Codebase

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

Try Supermodel Free