vue 獲取元素高度


1、html
<div ref="getheight"></div> 

2、JavaScript // 獲取高度值 (內容高+padding+邊框) let height= this.$refs.getheight.offsetHeight; // 獲取元素樣式值 (存在單位) let height = window.getComputedStyle(this.$refs.getheight).height; //獲取元素內聯樣式值(非內聯樣式無法獲取) let height = this.$refs.getheight.style.height; // 注意:要在元素渲染出來才能獲取元素的高度 實例: mounted(){ this.$nextTick(()=>{ // 頁面渲染完成后的回調 console.log(this.$refs.getheight.offsetHeight) }) }

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM