项目中使用vue+typescript使用this.$refs.refsName和document.querySelector打印出来的结果是一样的但是当使用API是。$refs获得的DOM就报错:请问是需要在ts项目中添加什么ts相关的配置吗?Property 'getBoundingClientRect' does not exist on type 'Vue | Element | Vue[] | Element[]'. Property 'getBoundingClientRect' does not exist on type 'Vue'.any let el = this.$refs.refsName console.log('el:', el); let element = document.querySelector('.content-box') console.log('element:', el); console.log(element['style'].width) // 1.element 调用API正常 console.log(window.getComputedStyle(element).width) console.log(element.getBoundingClientRect()) // 2.el 调用报错 // Property 'getBoundingClientRect' does not exist on type 'Vue | Element | Vue[] | Element[]'.Property 'getBoundingClientRect' does not exist on type 'Vue'.any // console.log(el.getBoundingClientRect()) // console.log(window.getComputedStyle(el).width)知道了,要把let el = this.$refs.refsName改为:let el: any = this.$refs.refsName,定义一个类型
添加回答
举报
0/150
提交
取消