dom 结构
<div id="id1" class="class1" ref="ref1" style="width: 100px; height: 100px;"></div>
通过 id 获取高度宽度
let widthid1 = document.getElementById("id1").offsetWidth
let heightid = document.getElementById("id1").offsetHeight
通过class 获取高度宽度
let widthclass1 = document.getElementsByClassName("class1").offsetWidth
let heightclass1 = document.getElementsByClassName("class1").offsetHeight
通过ref 获取高度宽度
let widthref1 = this.$refs.ref1.offsetWidth
let heightref1 = this.$refs.ref1.offsetHeight
原文链接:https://blog.csdn.net/qq_38946996/article/details/118270528