獲取高度:
<div ref="自定義名稱" >
</div>
要在鈎子mounted里面dom結構生成后去獲取dom的高度,寬度,修改樣式等操作!!!
mounted() { let h = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; //瀏覽器高度 let topH = this.$refs.topInfo.offsetHeight; console.log() let tabH = this.$refs.tab.offsetHeight; console.log() let subH = this.$refs.subBtn.offsetHeight; console.log() let scrollHight = this.$refs.scroller.offsetHeight this.height = (h - topH - tabH - subH) + "px" //localStorage.setItem("access_token", '52ecda6ecb4a11e7bd2a00163e0891fd') //測試token this.queryData(0) let w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;//瀏覽器寬度 } //獲取dom元素高度通過在標簽里面定義ref屬性,用this.$refs.自定義名稱.offsetHight;去獲取。
還有其他獲取指定高度的方式:
//獲取元素樣式值,為元素ref="ele"(在樣式里面寫死了的高度) var heightCss = window.getComputedStyle(this.$refs.ele).height; // ?px
//獲取元素內聯樣式值 var heightStyle =this.$refs.ele.style.height; // ?px
內容原創,轉載請注明出處!!!!謝謝合作!