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
  0172bfc6_ac03_78a5_d338_b37f7a86af7a["initSetup()"]
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289["initState()"]
  a45b86d7_95dc_3c82_51a7_1bc8c4d23289 -->|calls| 0172bfc6_ac03_78a5_d338_b37f7a86af7a
  1cce23c5_c59e_9843_86a6_04dfc6049dcd["createSetupContext()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 1cce23c5_c59e_9843_86a6_04dfc6049dcd
  387f4cc0_d1d8_687f_b954_207658b1a562["setCurrentInstance()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 387f4cc0_d1d8_687f_b954_207658b1a562
  0f6ffc11_2e95_459d_b27e_bbd8d5d18e4a["pushTarget()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 0f6ffc11_2e95_459d_b27e_bbd8d5d18e4a
  5e0e8149_c084_bc65_f3b4_53709d2e0da8["shallowReactive()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 5e0e8149_c084_bc65_f3b4_53709d2e0da8
  a51c7238_0b82_ad88_085b_cd519eb78568["popTarget()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| a51c7238_0b82_ad88_085b_cd519eb78568
  b6885901_8acd_8c4a_af15_cbd768bcd57b["isFunction()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| b6885901_8acd_8c4a_af15_cbd768bcd57b
  3d975ef8_6070_36a5_82f8_9180576e2ca1["isObject()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 3d975ef8_6070_36a5_82f8_9180576e2ca1
  0c0e51d9_10d5_5aee_bedb_8decee4220fe["proxyWithRefUnwrap()"]
  0172bfc6_ac03_78a5_d338_b37f7a86af7a -->|calls| 0c0e51d9_10d5_5aee_bedb_8decee4220fe
  style 0172bfc6_ac03_78a5_d338_b37f7a86af7a 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

Called By

Frequently Asked Questions

What does initSetup() do?
initSetup() is a function in the vue codebase.
What does initSetup() call?
initSetup() calls 8 function(s): createSetupContext, isFunction, isObject, popTarget, proxyWithRefUnwrap, pushTarget, setCurrentInstance, shallowReactive.
What calls initSetup()?
initSetup() 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