MCPcopy
hub / github.com/vuejs/core / mount

Function mount

packages/runtime-core/src/apiCreateApp.ts:358–419  ·  view source on GitHub ↗
(
        rootContainer: HostElement,
        isHydrate?: boolean,
        namespace?: boolean | ElementNamespace,
      )

Source from the content-addressed store, hash-verified

356 },
357
358 mount(
359 rootContainer: HostElement,
360 isHydrate?: boolean,
361 namespace?: boolean | ElementNamespace,
362 ): any {
363 if (!isMounted) {
364 // #5571
365 if (__DEV__ && (rootContainer as any).__vue_app__) {
366 warn(
367 `There is already an app instance mounted on the host container.\n` +
368 ` If you want to mount another app on the same host container,` +
369 ` you need to unmount the previous app by calling \`app.unmount()\` first.`,
370 )
371 }
372 const vnode = app._ceVNode || createVNode(rootComponent, rootProps)
373 // store app context on the root VNode.
374 // this will be set on the root instance on initial mount.
375 vnode.appContext = context
376
377 if (namespace === true) {
378 namespace = 'svg'
379 } else if (namespace === false) {
380 namespace = undefined
381 }
382
383 // HMR root reload
384 if (__DEV__) {
385 context.reload = () => {
386 const cloned = cloneVNode(vnode)
387 // avoid hydration for hmr updating
388 cloned.el = null
389 // casting to ElementNamespace because TS doesn't guarantee type narrowing
390 // over function boundaries
391 render(cloned, rootContainer, namespace as ElementNamespace)
392 }
393 }
394
395 if (isHydrate && hydrate) {
396 hydrate(vnode as VNode<Node, Element>, rootContainer as any)
397 } else {
398 render(vnode, rootContainer, namespace)
399 }
400 isMounted = true
401 app._container = rootContainer
402 // for devtools and telemetry
403 ;(rootContainer as any).__vue_app__ = app
404
405 if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
406 app._instance = vnode.component
407 devtoolsInitApp(app, version)
408 }
409
410 return getComponentPublicInstance(vnode.component!)
411 } else if (__DEV__) {
412 warn(
413 `App has already been mounted.\n` +
414 `If you want to remount the same app, move your app creation logic ` +
415 `into a factory function and create fresh app instances for each ` +

Callers 1

index.tsFile · 0.50

Calls 6

warnFunction · 0.90
cloneVNodeFunction · 0.90
devtoolsInitAppFunction · 0.90
hydrateFunction · 0.85
renderFunction · 0.70

Tested by

no test coverage detected