vue-elementui树组件添加连接线

2022/4/23 6:14:11

本文主要是介绍vue-elementui树组件添加连接线,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

<template>
  <el-tree :data="data" default-expand-all :props="defaultProps" @node-click="handleNodeClick" />
</template>

<script>
export default {
  name: 'Dashboard',
  data() {
    return {
      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'
            }, {
              label: '三级 3-2-2'
            }]
          }]
        }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    }
  },
  methods: {
    handleNodeClick(data) {
      console.log(data)
    }
  }
}
</script>

<style lang="scss" scoped>
  .el-tree ::v-deep {
    .el-tree-node__content {
      position: relative;
    }

    .el-tree-node:last-child > .el-tree-node__content::before {
      content: "";
      width: 1px;
      height: 10000px;
      background-color: green;
      position: absolute;
      margin-left: -9px;
      bottom: 13px;
    }

    .el-tree-node__children .el-tree-node__content::after {
      content: "";
      width: 9px;
      height: 1px;
      background-color: red;
      position: absolute;
      margin-left: -9px;
    }

    .el-tree-node__content > .el-tree-node__expand-icon {
      padding: 6px 3px;
    }
  }
</style>
<!-- <style lang="scss" scoped>
  /* 方式二的思路 */
  .el-tree ::v-deep {
    .el-tree-node__children {
      padding-left: 24px;

      .el-tree-node::before {
        height: 100%;
        top: -26px;
      }

      .el-tree-node:last-child::before {
        height: 38px;
      }
    }
  }
</style> -->


这篇关于vue-elementui树组件添加连接线的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程