el-tree默认选中高亮第一个
时间: 2023-08-16 16:17:14 浏览: 181
要实现el-tree默认选中高亮第一个节点,可以使用以下方法:首先,设置el-tree的highlight-current属性为true,以启用高亮显示功能。其次,给el-tree设置一个ref属性,例如ref="tree",以便后续进行操作。然后,通过typescript来设置高亮显示的节点。在组件的mounted生命周期钩子函数中,使用this.$nextTick()方法来确保el-tree已经渲染完成。在nextTick的回调函数中,使用this.$refs.tree.setCurrentKey()方法来设置当前选中的节点。将要选中的节点的id作为setCurrentKey()方法的参数传入即可。例如,this.$refs.tree.setCurrentKey(this.treeData\[0\].id)可以将第一个节点设置为默认选中高亮的节点。\[1\]\[2\]
#### 引用[.reference_title]
- *1* [Elementui el-tree默认选中第一个,并实现高亮效果](https://blog.csdn.net/GFFcheng/article/details/121747950)[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^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [el-tree 默认选中并高亮显示](https://blog.csdn.net/zhengzzzzz/article/details/125557451)[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^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [el-tree默认选中并高亮显示](https://blog.csdn.net/zyj_princess/article/details/84858861)[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^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文