获取元素高度的方式

发布于 2022-01-11  100 次阅读


获取高度:

  <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


一沙一世界,一花一天堂。君掌盛无边,刹那成永恒。