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-09-26 22:35:37 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
active (value) {
|
|
|
|
if (value && !this.contentContainerMounted) {
|
|
|
|
this.contentContainerMounted = true
|
|
|
|
this.appendContent()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
contentContainer: null,
|
|
|
|
contentContainerMounted: false
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
detachContent () {
|
2019-09-26 22:35:37 +08:00
|
|
|
this.contentContainer = this.$refs.contentContainer
|
2019-08-16 16:45:26 +08:00
|
|
|
this.$refs.contentContainer.parentNode.removeChild(this.$refs.contentContainer)
|
2019-09-26 22:35:37 +08:00
|
|
|
},
|
|
|
|
appendContent () {
|
2019-08-16 16:45:26 +08:00
|
|
|
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()
|
2019-09-26 22:35:37 +08:00
|
|
|
// this.appendContent()
|
2019-07-11 19:51:59 +08:00
|
|
|
},
|
|
|
|
beforeDestroy () {
|
2019-09-26 22:35:37 +08:00
|
|
|
this.detachTarget.removeChild(this.$refs.contentContainer)
|
2019-07-11 19:51:59 +08:00
|
|
|
}
|
|
|
|
}
|