feat(runtime-core): support app.unmount(container) (#601)

close #593
This commit is contained in:
likui
2020-01-17 01:23:47 +08:00
committed by Evan You
parent 8ec69cbc3f
commit 04ac6c467a
3 changed files with 38 additions and 1 deletions

View File

@@ -29,7 +29,7 @@ export const createApp = (): App<Element> => {
})
}
const mount = app.mount
const { mount, unmount } = app
app.mount = (component, container, props): any => {
if (isString(container)) {
container = document.querySelector(container)!
@@ -52,6 +52,18 @@ export const createApp = (): App<Element> => {
return mount(component, container, props)
}
app.unmount = container => {
if (isString(container)) {
container = document.querySelector(container)!
if (!container) {
__DEV__ &&
warn(`Failed to unmount app: mount target selector returned null.`)
return
}
}
unmount(container)
}
return app
}