feat(runtime-dom): support using mount target innerHTML as template

This commit is contained in:
Evan You
2019-10-24 21:58:34 -04:00
parent ed29af7bea
commit 6a92bbd9c0
3 changed files with 47 additions and 27 deletions

View File

@@ -18,7 +18,7 @@ export interface App<HostElement = any> {
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
@@ -141,7 +141,7 @@ export function createAppAPI<HostNode, HostElement>(
mount(
rootComponent: Component,
rootContainer: string | HostElement,
rootContainer: HostElement,
rootProps?: Data
): any {
if (!isMounted) {

View File

@@ -123,7 +123,7 @@ export interface RendererOptions<HostNode = any, HostElement = any> {
export type RootRenderFunction<HostNode, HostElement> = (
vnode: VNode<HostNode, HostElement> | null,
dom: HostElement | string
dom: HostElement
) => void
/**
@@ -1858,19 +1858,12 @@ export function createRenderer<
}
}
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)