提交 d6014381 编写于 作者: D dolymood

fix issue #31

上级 75beb107
......@@ -24,8 +24,12 @@ export default function createAPIComponent(Vue, Component, events = [], single =
const originRemove = component.remove
component.remove = function () {
if (instance.__cube__destroyed) {
return
}
originRemove && originRemove.call(this)
instance.destroy()
instance.__cube__destroyed = true
if (instanceSingle) {
singleComponent = null
singleInstance = null
......@@ -49,7 +53,20 @@ export default function createAPIComponent(Vue, Component, events = [], single =
return component
},
create(config, renderFn, single) {
return api.open(parseRenderData(config, events), renderFn, single)
const ownerInstance = this
const component = api.open(parseRenderData(config, events), renderFn, single)
if (component.__cube__parent !== ownerInstance) {
component.__cube__parent = ownerInstance
const beforeDestroy = function () {
if (component.__cube__parent === ownerInstance) {
component.remove()
}
ownerInstance.$off('hook:beforeDestroy', beforeDestroy)
component.__cube__parent = null
}
ownerInstance.$on('hook:beforeDestroy', beforeDestroy)
}
return component
}
}
return api
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册