BeforeDestroy cannot get the height of the ref scroll bar

beforeDestroy(){
        console.log("scrollTop-",this.$refs.main.scroller.scrollTop)
 
      },
  

clipboard.png

the scroll bar height of ref cannot be obtained in the beforeDestroy cycle. In created, I can use a timer to get it. To find a solution, or to monitor the scroll bar height of ref, ask everyone who has encountered it to solve

.
Apr.20,2022

in beforeDestroy , although the instance still exists, the height of the container is already 0, so the value of the scroll bar is also 0

.

timer is not recommended. You can get the height in mounted , when the dom has been loaded. If you have an asynchronous data request, you should write the acquisition height in the hook after getting the data

.

bind the listening event of the scroll bar in mounted and record the height value of the scroll bar on the instance

  beforeDestroy () {
    console.log(this.scrollTopRecord)
    this.$refs.main.scroller.removeEventListener('scroll', this.recordScroll)
  }
Menu