vue3el-input获取焦点
时间: 2023-08-16 07:04:54 浏览: 972
在Vue3中,要让el-input获取焦点,可以使用自定义指令来实现。根据引用\[3\]中的代码示例,你可以在directives中注册一个局部的自定义指令v-focus,并在mounted钩子函数中使用el.children\[0\].focus()来获取el-input内部的input元素,并使其获取焦点。这样,当el-input渲染完成后,input元素会自动获取焦点。
#### 引用[.reference_title]
- *1* [Vue3.0ElementPlus<input输入框自动获取焦点>](https://blog.csdn.net/weixin_45684041/article/details/125276695)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Vue(ts) - ref & $refs 之el-input获取焦点](https://blog.csdn.net/qq_33242126/article/details/123929054)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [【vue3】el-input 的获取焦点——el挂载:自定义指令,focus使 input 获取焦点(el-input 的Input Methods...](https://blog.csdn.net/qinglingLS/article/details/117536589)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文