vue+ts使用$refs属性报错Property 'focus' does not exist on type 'Vue | Element | (Vue | Element)[]'

问题

项目中直接使用
this.$refs.searchInput.focus()
会报以下错误
Property 'focus' does not exist on type 'Vue | Element | (Vue | Element)[]'

原因

ts中类型不明确引起的

解决

先定义searchInput的类型,再进行后续操作
let SI:any=this.$refs.searchInput
SI.focus()
posted @ 2022-07-25 08:59  huihuihero  阅读(1370)  评论(0编辑  收藏  举报