Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

https://element.eleme.cn/2.6/...

这里有个问题,设置自动获得焦点的时候,官方的例子里为什么这样写

this.$refs.saveTagInput.$refs.input.focus();

为什么调用了两次$refs
我的理解是一个refs就够了啊,就像这样:

this.$refs.saveTagInput.focus();

image.png
image.png

请各位大神指点一下,非常感谢!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
3.4k views
Welcome To Ask or Share your Answers For Others

1 Answer

因为最后期望的是聚焦到 input 输入框,也就是要操作 input

this.$refs.saveTagInputel-input 组件实例,this.$refs.saveTagInput.$refs.input 才是真正的 input 元素。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...