Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

elementUI 2.6动态编辑标签问题

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

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

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

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

this.$refs.saveTagInput.focus();

image.png
image.png

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...