当前位置:   article > 正文

VUE3+elementPlus的el-tree添加右键菜单_el-tree右键显示新增

el-tree右键显示新增
  1. <el-tree
  2. ref="treeRef"
  3. :data="listData"
  4. :props="defaultProps"
  5. @node-click="handleNodeClick"
  6. @node-contextmenu="rightClick"
  7. />
  8. <div class="rightMenu" v-show="showRightMenu">
  9. <ul>
  10. <li @click="addMenu">
  11. <el-icon>
  12. <CirclePlus />
  13. </el-icon>新建同级
  14. </li>
  15. <li @click="addSonMenu">
  16. <el-icon>
  17. <CirclePlus />
  18. </el-icon>新建子级
  19. </li>
  20. <li @click="delMenu">
  21. <el-icon>
  22. <CircleClose />
  23. </el-icon>删除功能
  24. </li>
  25. </ul>
  26. </div>
  27. <script>
  28. const showRightMenu = ref(false)
  29. const rightClick = (event, data, node, json) => {
  30. showRightMenu.value = false
  31. let menu = document.querySelector('.rightMenu')
  32. menu.style.left = event.clientX + 'px'
  33. menu.style.top = event.clientY + 'px'
  34. showRightMenu.value = true
  35. document.addEventListener('click', show)
  36. }
  37. const show = () => {
  38. showRightMenu.value = false
  39. }
  40. </script>
  41. <style scoped>
  42. //样式可以自己定义
  43. .rightMenu {
  44. position: fixed;
  45. z-index: 99999999;
  46. cursor: pointer;
  47. border: 1px solid #eee;
  48. box-shadow: 0 0.5em 1em 2px rgba(0, 0, 0, 0.1);
  49. border-radius: 6px;
  50. color: #1a1a1a;
  51. }
  52. .rightMenu ul {
  53. list-style: none;
  54. margin: 0;
  55. padding: 0;
  56. border-radius: 6px;
  57. }
  58. .rightMenu ul li {
  59. padding: 6px 10px;
  60. background: #fff;
  61. border-bottom: 1px solid #000;
  62. box-sizing: border-box;
  63. display: flex;
  64. align-items: center;
  65. justify-content: space-around;
  66. }
  67. .rightMenu ul li:last-child {
  68. border: none;
  69. }
  70. .rightMenu ul li:hover {
  71. transition: all 1s;
  72. background: #92c9f6;
  73. }
  74. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/119227?site
推荐阅读
相关标签
  

闽ICP备14008679号