当前位置: 首页 > news >正文

el-tree 点击父节点无效,只能选中子节点

背景:

el-tree树形控件点击的时候,我们不希望点击父节点,只希望点击子节点触发效果。

实际使用示例:摄像头树状图,根据不同市级区域划分,我们只希望点击子节点【摄像头】有效,点击具体的摄像头调取网络接口,点击市级区域不调取接口。

官网示例:

官网示例代码:

<template><el-treestyle="max-width: 600px":data="data":props="defaultProps"default-expand-all@node-click="handleNodeClick"/>
</template><script lang="ts" setup>
interface Tree {label: stringchildren?: Tree[]
}const handleNodeClick = (data: Tree) => {console.log(data)
}const data: Tree[] = [{label: 'Level one 1',children: [{label: 'Level two 1-1',children: [{label: 'Level three 1-1-1',},],},],},{label: 'Level one 2',children: [{label: 'Level two 2-1',children: [{label: 'Level three 2-1-1',},],},{label: 'Level two 2-2',children: [{label: 'Level three 2-2-1',},],},],},{label: 'Level one 3',children: [{label: 'Level two 3-1',children: [{label: 'Level three 3-1-1',},],},{label: 'Level two 3-2',children: [{label: 'Level three 3-2-1',},],},],},
]const defaultProps = {children: 'children',label: 'label',
}
</script>

备注:从上面这个示例我们可以知道,点击父节点或者点击子节点都会触发节点点击事件,即触发节点点击事件@node-click="handleNodeClick"

要想仅仅点击子节点触发事件@node-click="handleNodeClick",需要在handleNodeClick事件内部判断点击的是否是子节点或者父节点,满足条件在执行,否则不执行。

实际效果图:

备注:在这个实际代码中,我们就可以判断type=== 100是否满足条件,满足的执行,不满足的不执行。

http://www.dtcms.com/a/364396.html

相关文章:

  • 存算一体:重构AI计算的革命性技术(3)
  • 2025 大数据时代值得考的证书排名前八​
  • 电子病历空缺句的语言学特征描述与自动分类探析(以GPT-5为例)(上)
  • 分布式AI算力系统番外篇-----超体的现实《星核》
  • 2025版基于springboot的电影购票管理系统
  • Linux_网络基础
  • Uniapp中进行微信小程序头像和昵称的更改
  • Jenkins 可观测最佳实践
  • Flutter Android真机器调式,虚拟机调试以及在Vscode中开发Flutter应用
  • 【Linux操作系统】简学深悟启示录:进程控制
  • unity中的交互控制脚本
  • 如何选择适合企业的海外智能客服系统:6 大核心维度 + 实战选型指南
  • 【STL源码剖析】从源码看 deque :拆解双端队列的底层实现与核心逻辑
  • 用友T3、T6/U8批量作废凭证
  • 从数据生成到不确定性估计:用 LSTM + 贝叶斯优化实现时间序列多步预测
  • 基于SpringBoot的旅游管理系统
  • 【大前端】React 使用 Redux 实现组件通信的 Demo 示例
  • React实现点击按钮复制操作【navigator.clipboard与document.execCommand】
  • 基于单片机PWM信号发生器系统Proteus仿真(含全部资料)
  • 平衡车 - 电机调速
  • 基于单片机车内换气温度检测空气质量检测系统Proteus仿真(含全部资料)
  • 单片机点灯
  • Linux 网络编程中核心函数`recv`。
  • zynq 开发系列 新手入门:GPIO 连接 MIO 控制 LED 闪烁(SDK 端代码编写详解)
  • Spring Boot 实现数据库表变更监听的 Redis 消息队列方案
  • 单片机控制两只直流电机正反转C语言
  • 变频器实习DAY42 VF与IF电机启动方式
  • Excel 电影名匹配图片路径教程:自动查找并写入系统全路径
  • wpf 自定义控件,只能输入小数点,并且能控制小数点位数
  • 机器学习从入门到精通 - Python环境搭建与Jupyter魔法:机器学习起航必备