mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-21 04:50:14 +08:00
perf(mixin/placeable): register listeners on demand
This commit is contained in:
parent
61ea1063bb
commit
bd0584f319
@ -1,6 +1,5 @@
|
||||
import scrollDelegate from '../_utils/delegate/scrollDelegate'
|
||||
import resizeDelegate from '../_utils/delegate/resizeDelegate'
|
||||
import getParentNode from '../_utils/dom/getParentNode'
|
||||
import getScrollParent from '../_utils/dom/getScrollParent'
|
||||
import {
|
||||
getAdjustedPlacementOfTrackingElement,
|
||||
@ -169,6 +168,11 @@ export default {
|
||||
watch: {
|
||||
active (value) {
|
||||
if (value) {
|
||||
if (this.listenersRegistered) {
|
||||
this.registerScrollListeners()
|
||||
this.registerResizeListener()
|
||||
this.listenersRegistered = true
|
||||
}
|
||||
this.$nextTick().then(this.updatePosition)
|
||||
}
|
||||
},
|
||||
@ -184,17 +188,23 @@ export default {
|
||||
trackingElement: null,
|
||||
trackedElement: null,
|
||||
scrollListeners: [],
|
||||
adjustedPlacement: this.placement
|
||||
adjustedPlacement: this.placement,
|
||||
listenersRegistered: false
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.registerScrollListeners()
|
||||
this.registerResizeListener()
|
||||
if (this.active) {
|
||||
this.registerScrollListeners()
|
||||
this.registerResizeListener()
|
||||
this.listenersRegistered = true
|
||||
}
|
||||
this.updatePosition()
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.unregisterScrollListeners()
|
||||
this.unregisterResizeListener()
|
||||
if (this.listenersRegistered) {
|
||||
this.unregisterScrollListeners()
|
||||
this.unregisterResizeListener()
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
_getTrackingElement () {
|
||||
|
Loading…
Reference in New Issue
Block a user