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
  87ac0b39_9319_5c07_1390_906641a5c4fe["initSetup()"]
  7d6ab8ef_bd4c_49b2_1b21_a805de50af72["initState()"]
  7d6ab8ef_bd4c_49b2_1b21_a805de50af72 -->|calls| 87ac0b39_9319_5c07_1390_906641a5c4fe
  6827e187_9a52_5423_0fdc_05675ae269f2["createSetupContext()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| 6827e187_9a52_5423_0fdc_05675ae269f2
  f6cc67da_03fd_cbe1_8ffb_6aaf0358d6ae["setCurrentInstance()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| f6cc67da_03fd_cbe1_8ffb_6aaf0358d6ae
  4a87a208_8bf5_28ff_be4d_8df11d928f69["pushTarget()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| 4a87a208_8bf5_28ff_be4d_8df11d928f69
  ae14044b_ea73_c6de_2889_aff2cd0a567a["shallowReactive()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| ae14044b_ea73_c6de_2889_aff2cd0a567a
  f933dbd4_cb05_cc5c_162b_7ab5e35d316d["popTarget()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| f933dbd4_cb05_cc5c_162b_7ab5e35d316d
  5af21a52_5316_e857_22eb_dce69bb60268["isFunction()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| 5af21a52_5316_e857_22eb_dce69bb60268
  2d184c1f_e247_ef28_44f9_122886cfd2a5["isObject()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| 2d184c1f_e247_ef28_44f9_122886cfd2a5
  0dff7671_dbca_28ee_2e55_169d9e03ef4c["proxyWithRefUnwrap()"]
  87ac0b39_9319_5c07_1390_906641a5c4fe -->|calls| 0dff7671_dbca_28ee_2e55_169d9e03ef4c
  style 87ac0b39_9319_5c07_1390_906641a5c4fe 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