Element el-tree 树形的默认点击第一个node,并高亮

  • Post author:
  • Post category:其他


<el-tree
  class="filter-tree"
  :data="treeData"
  :props="treeProps"
  node-key="id"
  :highlight-current="true"   //是否高亮当前选中节点,默认值是 false。把它设置为true
  default-expand-all
  :filter-node-method="filterNode"
  ref="tree"
  @node-click="nodeClick">
</el-tree>
//后台返回数据
commodityclasstwobyone(params).then((res) => {
            this.treeData = res.data
            if(res.data.length > 0 ){
              //'nextTick()' 下次dom更新时触发回调函数
              //默认点击
              this.$nextTick().then(() =>{
                const firstNode = document.querySelector('.el-tree-node')
                firstNode.click();
              })
            }
          })


$nextTick详情 API



版权声明:本文为qq_42307369原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。