欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Vue ElementUI el-tree 组件鼠标双击事件

程序员文章站 2022-06-25 09:18:03
目前 element-ui 的 tree 控件不支持双击事件,但是这个时候有个需求,需要双击事件.没办法,只能自己写一个咯,记录下自己写的方法简单引用,添加@node-click事件

目前 element-ui 的 tree 控件不支持双击事件,但是这个时候有个需求,需要双击事件.
没办法,只能自己写一个咯,记录下自己写的方法

简单引用,添加@node-click事件

	<el-tree
            ref="tree"
            node-key="id"
            :data="treeData"
            :expand-on-click-node="false"
            @node-click="handleNodeClick">
    </el-tree>

在handleNodeClick事件中处理双击事件

data() {
    return {
    	//定义点击次数,默认0次
        treeClickCount: 0,
    }
},
methods: {
	//节点点击事件
	handleNodeClick(data, node) {
		//记录点击次数
		this.treeClickCount++;
		//单次点击次数超过2次不作处理,直接返回,也可以拓展成多击事件
		if (this.treeClickCount >= 2) {
			return;
		}
		//计时器,计算300毫秒为单位,可自行修改
		this.timer = window.setTimeout(() => {
			if (this.treeClickCount == 1) {
				//把次数归零
				this.treeClickCount = 0;
				//单击事件处理
				this.console('单击事件,可在此处理对应逻辑')
				
			} else if (this.treeClickCount > 1) {
				//把次数归零
				this.treeClickCount = 0;
				//双击事件
				this.console('双击事件,可在此处理对应逻辑')
			}
		}, 300);
	
	}
}

结束

本文地址:https://blog.csdn.net/q469731241/article/details/107356605