vue 获取元素高度

匿名 (未验证) 提交于 2019-12-02 23:56:01
1html <div ref="getheight"></div> <br><br> 2JavaScript // 获取高度值 (内容高+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)     }) }

 

   
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!