效果图
// html
<el-tree style="margin-top: 10px" :data="data" :props="defaultProps" @node-contextmenu="rightClick"></el-tree>
<div id="menu" v-show="menuVisible" @mouseleave="menuVisible=!menuVisible">
<el-card class="box-card">
<div class="text item">
<el-link icon="el-icon-circle-plus-outline" :underline="false">添加</el-link>
</div>
<div class="text item">
<el-link icon="el-icon-remove-outline" :underline="false">删除</el-link> </div>
</el-card>
</div>
// data
data(){
return {
menuVisible:false,
data: [{
label: '一级 1',
children: [{
label: '二级 1-1',
children: [{
label: '三级 1-1-1'
}]
}]
}, {
label: '一级 2',
children: [{
label: '二级 2-1',
children: [{
label: '三级 2-1-1'
}]
}, {
label: '二级 2-2',
children: [{
label: '三级 2-2-1'
}]
}]
}, {
label: '一级 3',
children: [{
label: '二级 3-1',
children: [{
label: '三级 3-1-1'
}]
}, {
label: '二级 3-2',
children: [{
label: '三级 3-2-1'
}]
}]
}],
defaultProps: {
children: 'children',
label: 'label'
}
}
}
methods:{
// 右键压下
rightClick(MouseEvent, object, Node, element) {
console.log(Node)
this.nodeData = Node
this.menuVisible = true;
let menu = document.querySelector("#menu");
menu.style.cssText = "position: fixed; left: " + (MouseEvent.clientX - 10) + 'px' + "; top: " + (MouseEvent.clientY - 25) + 'px; z-index: 999; cursor:pointer;';
},
}