再做一個滾動的功能,需要獲取到被滾動元素的高度代碼如下 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) })我發現得到的值并不是實際高度的值,最初我懷疑是不是數據沒有渲染進去,于是查看了一下DOM中屬性的值,發現內容都是有的,就連clientHeight的值也是我需要的準確的值,但是不知道為什么我獲取clientHeight值的時候卻并不是我想要的,我嘗試了使用定時器,但是結果還是一樣的當時間只有在1000的時候才能獲取到確切的高度;
在$nextTick中獲取DOM高度的問題
LEATH
2018-11-13 14:13:47