element ui 中el-tree修改背景色及选中的颜色鼠标悬停颜色

<template>
  <div class="layer">
    <div class="layer-left">
      <el-tree :data="data" :props="defaultProps" @node-click="handleNodeClick" class="custom-tree"
        :highlight-current="true"></el-tree>
    </div>
    <div class="layer-right"></div>
  </div>
</template>

<script>
export default {
  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'
            }]
          }]
        }
      ],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    };
  },
  methods: {
    handleNodeClick (data) {
      console.log(data);
    }
  }
};
</script>
<style lang="less" scoped>
.layer {
  display: flex;
  height: 100%;

  &-left {
    width: 322px;
    background: #00162A;
    border-radius: 0px 0px 0px 0px;
    border: 1px solid #939393;
    //鼠标悬停的备降色
    /deep/ .el-tree-node__content:hover {
      background: #1E374F;
    }

    //选中的背景色
    /deep/.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content {
      background-color: #1E374F;
    }

    //整体背景色
    /deep/.el-tree {
      background: #00162A;
      color: #ffffff;
    }
    //点击时背景色
    /deep/ .el-tree-node:focus>.el-tree-node__content {
      background-color: #1E374F;
    }
  }

  &-right {
    flex: 1;
  }
}
</style>

GitHub 加速计划 / eleme / element
10
1
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:4 个月前 )
c345bb45 8 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 8 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐