html部分:
<div ref="menuDiv"></div>
js部分:
1.offsetWidth、offsetHeight,返回Number类型,例如:200
。
let domWidth =this.$refs.menuDiv.offsetWidth; //宽度
let domHeight =this.$refs.menuDiv.offsetHeight;//高度
console.log(domWidth,domHeight)//打印dom的宽度,高度
2.window对象的getComputedStyleAPI,返回String类型,包含px单位,例如:"200px"。
let domWidth =window.getComputedStyle(this.$refs.menuDiv).width; //宽度
let domHeight =window.getComputedStyle(this.$refs.menuDiv).height;//高度
console.log(domWidth,domHeight)//打印dom的宽度,高度