To create another scrolling function, you need to obtain the height of the scrolled element
The code is as follows
created() { this.titleid = this.$route.params.titleid this.communityid = this.$route.params.communityid this.TOPIC_LOADORDERBY({titleid: this.titleid, communityid: this.communityid}) this.$nextTick(function () { // DOM 现在更新了 // `this` 绑定到当前实例 this._initScroll() let self = this; console.log(self.$refs.scorll.clientHeight) console.log(self.$refs) let height = self.$refs.scorll.clientHeight - self.$refs.topicReply.clientHeight; self.meunScroll.scrollTo(0, -height,0) })
I found that the value obtained was not the actual height value. At first, I suspected that the data was not rendered, so I checked the values of the attributes in the DOM and found that the content was there. Even the value of clientHeight was what I needed. The exact value, but I don’t know why when I get the clientHeight value it is not what I want. I tried using a timer, but the result is still the same. The exact height can only be obtained when the time is 1000;
In the created hook function, the template has not been rendered yet, try mounted