el-tree-select 节点禁止选择
时间: 2023-08-16 16:04:53 浏览: 124
el-tree-select节点禁止选择可以通过设置check-strictly属性为true来实现。在代码中,可以通过在node-click事件中判断节点的条件来禁止选择节点。例如,如果节点的parentId为'0',则禁止选择该节点。可以使用setCheckedKeys方法将选中的节点设置为空数组,以清空选中值。以下是一个示例代码:
```html
<el-tree-select ref="TreeSelectRef" style="width:100%" v-model="form.materialTypeId" :data="deptOptions" :props="{ value: 'id', label: 'materialType', children: 'children' }" value-key="id" placeholder="请选择物资类别" check-strictly @node-click="getGoodsTypeCode" />
```
```javascript
const getGoodsTypeCode = (node) => {
if (node && node.parentId === '0') {
proxy.$modal.msgWarning('请选择备品备件下面的类型')
TreeSelectRef.setCheckedKeys(\[\]) // 清空选中值禁止选择
form.value.materialTypeCode = ''
return false
}
if (node) {
form.value.materialTypeCode = node.materialTypeCode
form.value.materialType = node.materialType
}
}
```
在上述代码中,当节点的parentId为'0'时,会弹出警告提示,并将选中的节点设置为空数组,禁止选择该节点。
#### 引用[.reference_title]
- *1* [el-select 多选模式下嵌套el-tree 删除tag时能去掉el-tree对应节点的勾](https://blog.csdn.net/dabaoai123123/article/details/126075532)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Vue3+ElementPlus el-tree-select禁止选择根节点清空问题解决](https://blog.csdn.net/huichao199175/article/details/130982518)[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^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文