2019-09-17 19:27:48 +08:00
|
|
|
import withapp from './withapp'
|
|
|
|
|
2019-07-17 01:35:11 +08:00
|
|
|
/**
|
2019-08-16 16:45:26 +08:00
|
|
|
* Detach $refs.contentContainer to detachTarget
|
2019-07-17 14:40:28 +08:00
|
|
|
*
|
|
|
|
* Dependency:
|
2019-08-16 16:45:26 +08:00
|
|
|
* $refs.contentContainer
|
2019-07-17 14:40:28 +08:00
|
|
|
*
|
2019-08-16 16:45:26 +08:00
|
|
|
* @prop {HTMLElement} detachTarget determine where should $refs.contentContainer to be detached
|
2019-07-17 01:35:11 +08:00
|
|
|
*/
|
2019-07-11 19:51:59 +08:00
|
|
|
export default {
|
2019-09-17 19:27:48 +08:00
|
|
|
mixins: [withapp],
|
2019-07-11 19:51:59 +08:00
|
|
|
props: {
|
2019-07-17 01:35:11 +08:00
|
|
|
detachTarget: {
|
|
|
|
validator () {
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
default: () => document.body
|
2019-08-16 16:45:26 +08:00
|
|
|
},
|
|
|
|
cleanManually: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
detachContent () {
|
2019-08-16 16:45:26 +08:00
|
|
|
this.$refs.contentContainer.parentNode.removeChild(this.$refs.contentContainer)
|
|
|
|
this.detachTarget.append(this.$refs.contentContainer)
|
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-08-16 16:45:26 +08:00
|
|
|
if (!this.cleanManually) {
|
|
|
|
this.detachTarget.removeChild(this.$refs.contentContainer)
|
|
|
|
}
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
}
|