el-tree设置节点默认选中并高亮效果

javascript 复制代码
 <el-tree
        ref="tree"
        default-expand-all
        highlight-current
        check-on-click-node
        node-key="id"
        :data="treeData"
        :props="defaultProps"
        @node-click="nodeClick"
      >
      </el-tree>

  treeData: [],
      defaultProps: {
        children: "children",
        label: "columnName",
      },

      treeData: [],


    async getTree() {
      let obj = {};
      await columnList()
        .then((res) => {
          if (res.data && res.data.length > 0) {
            this.treeData = handleTree(res.data, "id");
            obj = this.treeData[0];
            this.$nextTick(() => {
              // todo 在这里设置
              this.$refs.tree.setCurrentKey(this.treeData[0].children[1].id)
            })
          } else {
            this.treeData = [];
            obj = {};
          }
          console.log("this.treeData", this.treeData)
        })
        .finally(() => {
          console.log(obj);
          this.nodeClick(obj);
        });
    },


  created() {
    this.getTree();
  },
javascript 复制代码
  // 设置首行高亮效果
  this.$refs.tree.setCurrentKey(this.treeData[0].id)
相关推荐
云水一下5 小时前
TypeScript 从零基础到精通(五):高级类型与泛型
前端·javascript·typescript
counterxing5 小时前
vibe coding 之后,我更不想打字了
前端·agent·ai编程
云水一下5 小时前
TypeScript 从零基础到精通(六):类型声明与模块化
javascript·typescript
copyer_xyf5 小时前
Python 模块与包的导入导出
前端·后端·python
研☆香5 小时前
es6新特性功能介绍(四)
前端·ecmascript·es6
微扬嘴角6 小时前
React篇1--JSX语法规则、组件、组件实例的3大特性
前端·react.js·前端框架
copyer_xyf6 小时前
Python venv 虚拟环境
前端·后端·python
无聊的老谢6 小时前
Vue 3 + TypeScript 构建大型电信运维平台的前端架构设计
前端·vue.js·typescript
xiaofeichaichai6 小时前
Map / Set / WeakMap / WeakSet
前端·javascript
李可以量化6 小时前
成交量的终极量化策略:价量共振指标完整实现(下篇)
前端·数据库·人工智能