HLJ 发布于
2021-12-02 15:58:59

element tree树组件默认背景色高亮显示

good博客 图片

1、html代码

<template>
  <el-tree 
  ref="treeBox"
  node-key="id"
  highlight-current
  default-expand-all
  :data="data" 
  :props="defaultProps"
  :expand-on-click-node="false">
  </el-tree>
</template>

2、js代码

export default {
  data() {
    return {
      data: [{
        id:1,
        label: '一级 1',
        children: [{
          id:2,
          label: '二级 1-1'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      }
    };
  },
  mounted(){
    this.$nextTick(() => {
      // 传入需要高亮的id
      this.$refs.treeBox.setCurrentKey(2);
    });
  }
}

3、css代码

.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content{
  background: #409eff!important;
  color: white!important;
}
当前文章内容为原创转载请注明出处:http://www.good1230.com/detail/2021-12-02/567.html
最后生成于 2023-06-27 21:38:00
此内容有帮助 ?
0