Problem getting DOM height in $nextTick - Stack Overflow
phpcn_u1582
phpcn_u1582 2017-05-19 10:09:37
0
1
504

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;

phpcn_u1582
phpcn_u1582

reply all(1)
给我你的怀抱

In the created hook function, the template has not been rendered yet, try mounted

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!