1. 程式人生 > >VUE獲取元素高度的方法

VUE獲取元素高度的方法

Vue獲取元素高度.

// 當前區域
<div ref="elememt"></div> 

// 獲取高度值 (內容高+padding+邊框)

let height= this.$refs.elememt.offsetHeight;  //100

// 獲取元素樣式值 (存在單位)

let height = window.getComputedStyle(this.$refs.element).height; // 100px

//獲取元素內聯樣式值(非內聯樣式無法獲取)

let height = this.$refs.element.style.height; // 100px