简体   繁体   English

如何在vue.js中将焦点切换到图像组件之类的按钮上

[英]How to tab focus on a button like image Component in vue.js

I have the following template in my vue.js application: 我的vue.js应用程序中有以下template

<div>
     <button class="button_text" @click="reset">Reset</button>
     <button class="button_text">Search</button>
     <image-component class="button_image_icon"/>
</div>

I am trying to set the tab focus on the <image-component> which is not a <button> but a Component with a label and input inside a <span> . 我试图将标签焦点设置在<image-component> ,这不是<button>而是带有label并在<span>内部inputComponent It sets focus on the buttons easily but not sure how to do it on an button like image icon. 它可以轻松地将焦点设置在按钮上,但是不确定如何在图像图标之类的按钮上进行操作。

Tried: @click="setFocus" , didn't work. 尝试: @click="setFocus" ,不起作用。

You should be able to achieve it by adding the tabindex attribute to all the elements 您应该可以通过向所有元素添加tabindex属性来实现它

<div>
     <button class="button_text" @click="reset" tabindex="1">Reset</button>
     <button class="button_text" tabindex="2">Search</button>
     <image class="button_image_icon" tabindex="3" />
</div>

Example with focus manually set with javascript: https://jsfiddle.net/qeugo6hm/5/ 使用javascript手动设置焦点的示例: https : //jsfiddle.net/qeugo6hm/5/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM