2019-07-17 01:35:11 +08:00
|
|
|
/**
|
2019-07-17 14:40:28 +08:00
|
|
|
* Detach $refs.contentWrapper to detachTarget
|
|
|
|
*
|
|
|
|
* Dependency:
|
|
|
|
* $refs.contentWrapper
|
|
|
|
*
|
|
|
|
* @prop {HTMLElement} detachTarget determine where should $refs.contentWrapper to be detached
|
2019-07-17 01:35:11 +08:00
|
|
|
*/
|
2019-07-11 19:51:59 +08:00
|
|
|
export default {
|
|
|
|
props: {
|
2019-07-17 01:35:11 +08:00
|
|
|
detachTarget: {
|
|
|
|
validator () {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
default: () => document.body
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
detachContent () {
|
2019-07-17 01:35:11 +08:00
|
|
|
this.$refs.contentWrapper.parentNode.removeChild(this.$refs.contentWrapper)
|
|
|
|
this.detachTarget.append(this.$refs.contentWrapper)
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount () {
|
|
|
|
if (!this.detachTarget) {
|
|
|
|
console.warn(this.$options.name, ' will be mounted to', this.detachTarget, ', but it doesn\'t exist! Modal component won\'t work!')
|
|
|
|
}
|
|
|
|
},
|
|
|
|
mounted () {
|
|
|
|
this.detachTarget = document.body // getScrollParent(this.$refs.self)
|
|
|
|
this.detachContent()
|
|
|
|
},
|
|
|
|
beforeDestroy () {
|
2019-07-17 01:35:11 +08:00
|
|
|
this.detachTarget.removeChild(this.$refs.contentWrapper)
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
}
|