ElementUI el-tree 树组件 增加辅助线

需求

项目需求给elementUI的el-tree添加辅助线,并且不能使用其他插件,没办法只能该样式了。

效果

代码

html

javascript 复制代码
<template>
  <div>
    <el-scrollbar class="long-content">
      <el-tree node-key="id"
               :data="deptTree"
               default-expand-all
               ref="deptTree">
        <span class="custom-tree-node"
              slot-scope="{ node }">
          <el-tooltip class="item"
                      effect="dark"
                      :content="node.label"
                      :open-delay="1000"
                      placement="right">
            <span style="font-size: 14px;">{{ node.label }}</span>
          </el-tooltip>
        </span>
      </el-tree>
    </el-scrollbar>
  </div>
</template>

css

javascript 复制代码
<style lang="scss" scoped>

.long-content {
  height: calc(100% - 40px);
  margin-top: 10px;
  box-sizing: border-box;

  ::v-deep {
    // 设置树形组件节点的定位和左内边距
    .el-tree-node {
      position: relative;
      // padding-left: 13px;
    }
    // 设置树形组件节点的 before 伪类的样式
    .el-tree-node:before {
      width: 1px;
      height: 100%;
      content: '';
      position: absolute;
      top: -38px;
      bottom: 0;
      left: 0;
      right: auto;
      border-width: 1px;
      border-left: 1px dashed #b8b9bb;
    }
    // 设置树形组件节点的 after 伪类的样式
    .el-tree-node:after {
      width: 13px;
      height: 13px;
      content: '';
      position: absolute;
      left: 0;
      right: auto;
      top: 11px;
      bottom: auto;
      border-width: 1px;
      border-top: 1px dashed #b8b9bb;
    }

    // 设置树形组件首节点的左边框不显示
    .el-tree > .el-tree-node:before {
      border-left: none;
    }

    // 设置树形组件首节点的顶部边框不显示
    .el-tree > .el-tree-node:after {
      border-top: none;
    }

    // 设置树形组件末节点的 before 伪类的高度
    .el-tree .el-tree-node:last-child:before {
      height: 50px;
    }

    // 设置树形组件节点字体大小、以及取消左内边距
    .el-tree .el-tree-node__content {
      color: #000;
      font-size: 14px;
      padding-left: 0 !important;
    }

    // 设置树形组件孩子节点左内边距
    .el-tree .el-tree-node__children {
      padding-left: 11.5px;
    }

    // 设置树形组件复选框左右外边距
    .el-tree .el-tree-node__content > label.el-checkbox {
      margin: 0 5px 0 5px !important;
    }

    // 设置树形组件展开图标定位、图层、内边距
    .el-tree .el-tree-node__expand-icon {
      position: relative;
      z-index: 99;
    }

    // 设置树形组件叶子节点的默认图标不显示
    .el-tree .el-tree-node__expand-icon.is-leaf {
      display: none;
    }

    // 设置树形组件叶子节点的横线
    .el-tree .leaf-node-line {
      width: 23px;
      height: 13px;
      content: '';
      position: absolute;
      left: 13px;
      right: auto;
      top: 12px;
      bottom: auto;
      border-width: 1px;
      border-top: 1px solid #b8b9bb;
    }

    // 设置树形组件有叶子节点的左外边距
    .el-tree .el-tree-node__content:has(.is-leaf) {
      // color: aqua;
      margin-left: 24px !important;
    }
  }
}
</style>
相关推荐
锋行天下1 天前
半秒开!还有谁!!!
前端·vue.js·架构
JING小白1 天前
Day 1 重学Vue:响应式系统的“底层逻辑”变更,Vue2旧时代的终结与Vue3新时代的开启
前端·vue.js
OpenTiny社区1 天前
从零开发 AI 聊天页要两周?试试这款 Vue3 垂直对话组件库 TinyRobot,直接开箱即用
前端·vue.js·github
Cobyte1 天前
22.Vue Vapor 组件 props 的实现
前端·javascript·vue.js
白雾茫茫丶1 天前
探索 Nuxt.js 全栈能力:用 Better-Auth 打造类型安全的 RBAC 权限系统
前端·vue.js·nuxt.js
向阳而生6601 天前
文件上传也能玩出花?Vue3 教你优雅实现“选择文件”和“选择文件夹”🚀
vue.js
3630458411 天前
Signal 带来的架构问题思考
前端·vue.js
古夕2 天前
第三方 SSO 接入实践:redirect_uri 编码、回调一致性与跨项目联调
前端·vue.js
Ruihong2 天前
Vue withDefaults 转 React:VuReact 怎么处理?
vue.js·react.js·面试
稀土熊猫君2 天前
一个人能做出什么开源项目?
vue.js·后端·开源