naive-ui/packages/mixins/zindexable.js

41 lines
916 B
JavaScript
Raw Normal View History

2019-07-26 16:26:59 +08:00
import zIndexManager from '../utils/dom/zIndexManager'
/**
* watch active on component,
* acquire new z-index on content when active is set to true
*
* dependency:
* $refs.contentContainer
2019-07-26 16:26:59 +08:00
* $vm.active
* $vm.detached
2019-07-26 16:26:59 +08:00
*/
export default {
mounted () {
if (!this.detached) return
2019-09-02 18:30:53 +08:00
zIndexManager.registerElement(this._getZindexableContent())
2019-07-26 16:26:59 +08:00
},
watch: {
active (value) {
if (!this.detached) return
console.debug('[zindexable.watch.active]:', value)
if (value) {
2019-09-02 18:30:53 +08:00
zIndexManager.setNewZIndex(this._getZindexableContent())
2019-07-26 16:26:59 +08:00
}
}
},
beforeDestroy () {
if (!this.detached) return
2019-09-02 18:30:53 +08:00
zIndexManager.unregisterElement(this._getZindexableContent())
},
methods: {
_getZindexableContent () {
if (this.$refs.contentContainer) {
return this.$refs.contentContainer
} else {
return this.getZindexableContent()
}
}
2019-07-26 16:26:59 +08:00
}
}