element.getBoundingClientRect is not a function
时间: 2023-08-26 10:13:41 浏览: 267
解决vue里碰到 $refs 的问题的方法
报错"TypeError: this.$refs在Vue中,this.$refs返回的是VueComponent,而不是DOM元素。解决这个问题的方法是使用this.$refs你可以通过使用document.getElementById()或者其他方法来获取正确的DOM元素,然后再使用getBoundingClientRect()方法。例如,你可以使用var cvs = document.getElementById("myCanvas")来获取正确的canvas元素,然后再调用cvs.getBoundingClientRect()方法来获取canvas的位置和大小。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [vue中使用getBoundingClientRect()获取元素位置报错](https://blog.csdn.net/m0_38010595/article/details/112188554)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* [“TypeError: that.$refs.videoItem.getBoundingClientRect is not a function](https://blog.csdn.net/weixin_45503820/article/details/108641910)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
- *3* [关于ctx.addEventListener is not a function的报错问题,以及获取canvas中鼠标点击的位置坐标](https://blog.csdn.net/qq_49721447/article/details/112556575)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文