el-tree 怎么获取选中的数据
时间: 2023-10-19 07:25:00 浏览: 161
el-tree-selected-tree
要获取el-tree中选中的数据,可以使用以下方法:this.$refs.tree.getCheckedKeys()。这个方法会返回一个数组,包含了选中节点的id。但是需要注意的是,该方法只能获取到选中节点的id,无法获取到父节点的id。如果需要同时获取到选中节点和父节点的id,可以使用下面的方法:
let checkedData = this.$refs.tree.getCheckedKeys().concat(this.$refs.tree.getHalfCheckedKeys())。这样可以获取到所有选中节点和半选中节点的id,其中半选中节点是指部分子节点被选中但父节点未被选中的情况。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [el-tree 获取选中的值](https://blog.csdn.net/wwf1225/article/details/115354365)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [el-tree-selected-tree](https://download.csdn.net/download/Chinese521/13115150)[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^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文