日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

this ts 方法获取_vue+typescript项目中用this.$refs和原生方法获取的dom有什么区别

發(fā)布時間:2024/9/19 vue 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 this ts 方法获取_vue+typescript项目中用this.$refs和原生方法获取的dom有什么区别 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

項目中使用vue+typescript

使用this.$refs.refsName和document.querySelector打印出來的結(jié)果是一樣的

但是當使用API是。$refs獲得的DOM就報錯:請問是需要在ts項目中添加什么ts相關(guān)的配置嗎?

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 調(diào)用API正常

console.log(window.getComputedStyle(element).width)

console.log(element.getBoundingClientRect())

// 2.el 調(diào)用報錯

// 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,定義一個類型

與50位技術(shù)專家面對面20年技術(shù)見證,附贈技術(shù)全景圖

總結(jié)

以上是生活随笔為你收集整理的this ts 方法获取_vue+typescript项目中用this.$refs和原生方法获取的dom有什么区别的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。