directive(name: string, directive: Directive): this
mount(
rootComponent: Component,
- rootContainer: HostElement,
+ rootContainer: HostElement | string,
rootProps?: Data
): ComponentPublicInstance
provide<T>(key: InjectionKey<T> | string, value: T): void
mount(
rootComponent: Component,
- rootContainer: string | HostElement,
+ rootContainer: HostElement,
rootProps?: Data
): any {
if (!isMounted) {
export type RootRenderFunction<HostNode, HostElement> = (
vnode: VNode<HostNode, HostElement> | null,
- dom: HostElement | string
+ dom: HostElement
) => void
/**
}
}
- function render(vnode: HostVNode | null, rawContainer: HostElement | string) {
- let container: any = rawContainer
- if (isString(container)) {
- container = hostQuerySelector(container)
- if (!container) {
- if (__DEV__) {
- warn(
- `Failed to locate root container: ` + `querySelector returned null.`
- )
- }
- return
- }
+ const render: RootRenderFunction<
+ HostNode,
+ HostElement & {
+ _vnode: HostVNode | null
}
+ > = (vnode, container) => {
if (vnode == null) {
if (container._vnode) {
unmount(container._vnode, null, null, true)
-import { createRenderer } from '@vue/runtime-core'
+import { createRenderer, warn } from '@vue/runtime-core'
import { nodeOps } from './nodeOps'
import { patchProp } from './patchProp'
// Importing from the compiler, will be tree-shaken in prod
import { isHTMLTag, isSVGTag } from '@vue/compiler-dom'
+import { isFunction, isString } from '@vue/shared'
-const { render, createApp } = createRenderer<Node, Element>({
+const { render, createApp: baseCreateApp } = createRenderer<Node, Element>({
patchProp,
...nodeOps
})
-const wrappedCreateApp = () => {
- const app = createApp()
- // inject `isNativeTag` dev only
- Object.defineProperty(app.config, 'isNativeTag', {
- value: (tag: string) => isHTMLTag(tag) || isSVGTag(tag),
- writable: false
- })
+const createApp = () => {
+ const app = baseCreateApp()
+
+ if (__DEV__) {
+ // Inject `isNativeTag`
+ // this is used for component name validation (dev only)
+ Object.defineProperty(app.config, 'isNativeTag', {
+ value: (tag: string) => isHTMLTag(tag) || isSVGTag(tag),
+ writable: false
+ })
+ }
+
+ const mount = app.mount
+ app.mount = (component, container, props): any => {
+ if (isString(container)) {
+ container = document.querySelector(container)!
+ if (!container) {
+ __DEV__ &&
+ warn(`Failed to mount app: mount target selector returned null.`)
+ return
+ }
+ }
+ if (
+ __RUNTIME_COMPILE__ &&
+ !isFunction(component) &&
+ !component.render &&
+ !component.template
+ ) {
+ component.template = container.innerHTML
+ }
+ // clear content before mounting
+ container.innerHTML = ''
+ return mount(component, container, props)
+ }
+
return app
}
-const exportedCreateApp = __DEV__ ? wrappedCreateApp : createApp
-
-export { render, exportedCreateApp as createApp }
+export { render, createApp }
// DOM-only runtime helpers
export {