Home / Function/ $mount() — vue Function Reference

$mount() — vue Function Reference

Architecture documentation for the $mount() function in runtime-with-compiler.ts from the vue codebase.

Entity Profile

Dependency Diagram

graph TD
  83cfc556_24cd_7f8e_f154_30d3e26dcdba["$mount()"]
  04498845_3cc1_e86f_9070_0c7b23b88f7c["runtime-with-compiler.ts"]
  83cfc556_24cd_7f8e_f154_30d3e26dcdba -->|defined in| 04498845_3cc1_e86f_9070_0c7b23b88f7c
  994de652_da67_08a8_e9e9_9557640163bd["query()"]
  83cfc556_24cd_7f8e_f154_30d3e26dcdba -->|calls| 994de652_da67_08a8_e9e9_9557640163bd
  b06ba5c2_6218_9bc9_3501_8faf017f8f35["idToTemplate()"]
  83cfc556_24cd_7f8e_f154_30d3e26dcdba -->|calls| b06ba5c2_6218_9bc9_3501_8faf017f8f35
  7b793d8b_1f75_0bdc_7beb_4292960428ba["getOuterHTML()"]
  83cfc556_24cd_7f8e_f154_30d3e26dcdba -->|calls| 7b793d8b_1f75_0bdc_7beb_4292960428ba
  style 83cfc556_24cd_7f8e_f154_30d3e26dcdba fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/platforms/web/runtime-with-compiler.ts lines 21–92

Vue.prototype.$mount = function (
  el?: string | Element,
  hydrating?: boolean
): Component {
  el = el && query(el)

  /* istanbul ignore if */
  if (el === document.body || el === document.documentElement) {
    __DEV__ &&
      warn(
        `Do not mount Vue to <html> or <body> - mount to normal elements instead.`
      )
    return this
  }

  const options = this.$options
  // resolve template/el and convert to render function
  if (!options.render) {
    let template = options.template
    if (template) {
      if (typeof template === 'string') {
        if (template.charAt(0) === '#') {
          template = idToTemplate(template)
          /* istanbul ignore if */
          if (__DEV__ && !template) {
            warn(
              `Template element not found or is empty: ${options.template}`,
              this
            )
          }
        }
      } else if (template.nodeType) {
        template = template.innerHTML
      } else {
        if (__DEV__) {
          warn('invalid template option:' + template, this)
        }
        return this
      }
    } else if (el) {
      // @ts-expect-error
      template = getOuterHTML(el)
    }
    if (template) {
      /* istanbul ignore if */
      if (__DEV__ && config.performance && mark) {
        mark('compile')
      }

      const { render, staticRenderFns } = compileToFunctions(
        template,
        {
          outputSourceRange: __DEV__,
          shouldDecodeNewlines,
          shouldDecodeNewlinesForHref,
          delimiters: options.delimiters,
          comments: options.comments
        },
        this
      )
      options.render = render
      options.staticRenderFns = staticRenderFns

      /* istanbul ignore if */
      if (__DEV__ && config.performance && mark) {
        mark('compile end')
        measure(`vue ${this._name} compile`, 'compile', 'compile end')
      }
    }
  }
  return mount.call(this, el, hydrating)
}

Domain

Subdomains

Frequently Asked Questions

What does $mount() do?
$mount() is a function in the vue codebase, defined in src/platforms/web/runtime-with-compiler.ts.
Where is $mount() defined?
$mount() is defined in src/platforms/web/runtime-with-compiler.ts at line 21.
What does $mount() call?
$mount() calls 3 function(s): getOuterHTML, idToTemplate, query.

Analyze Your Own Codebase

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

Try Supermodel Free