mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-27 05:00:48 +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 scrollDelegate from '../_utils/delegate/scrollDelegate'
|
||||||
import resizeDelegate from '../_utils/delegate/resizeDelegate'
|
import resizeDelegate from '../_utils/delegate/resizeDelegate'
|
||||||
import getParentNode from '../_utils/dom/getParentNode'
|
|
||||||
import getScrollParent from '../_utils/dom/getScrollParent'
|
import getScrollParent from '../_utils/dom/getScrollParent'
|
||||||
import {
|
import {
|
||||||
getAdjustedPlacementOfTrackingElement,
|
getAdjustedPlacementOfTrackingElement,
|
||||||
@ -169,6 +168,11 @@ export default {
|
|||||||
watch: {
|
watch: {
|
||||||
active (value) {
|
active (value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
if (this.listenersRegistered) {
|
||||||
|
this.registerScrollListeners()
|
||||||
|
this.registerResizeListener()
|
||||||
|
this.listenersRegistered = true
|
||||||
|
}
|
||||||
this.$nextTick().then(this.updatePosition)
|
this.$nextTick().then(this.updatePosition)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -184,17 +188,23 @@ export default {
|
|||||||
trackingElement: null,
|
trackingElement: null,
|
||||||
trackedElement: null,
|
trackedElement: null,
|
||||||
scrollListeners: [],
|
scrollListeners: [],
|
||||||
adjustedPlacement: this.placement
|
adjustedPlacement: this.placement,
|
||||||
|
listenersRegistered: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.registerScrollListeners()
|
if (this.active) {
|
||||||
this.registerResizeListener()
|
this.registerScrollListeners()
|
||||||
|
this.registerResizeListener()
|
||||||
|
this.listenersRegistered = true
|
||||||
|
}
|
||||||
this.updatePosition()
|
this.updatePosition()
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
this.unregisterScrollListeners()
|
if (this.listenersRegistered) {
|
||||||
this.unregisterResizeListener()
|
this.unregisterScrollListeners()
|
||||||
|
this.unregisterResizeListener()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
_getTrackingElement () {
|
_getTrackingElement () {
|
||||||
|
Loading…
Reference in New Issue
Block a user