vue 获取dom节点 dom节点位置

tech2025-11-27  26

vue 获取dom

1.使用res <div class="cover" ref="div"></div> 2.使用this. r e f s [ ′ n a m e ′ ] 或 t h i s . refs['name'] 或 this. refs[name]this.refs.name,即可获取dom节点 this.$refs['div'] 3.获取dom的位置 getBoundingClientRect()可以打印出dom 的位置宽高等信息 this.$refs['div'].getBoundingClientRect() 4.offsetHeight与offsetWidth可以单独获取w与h

最新回复(0)