zoukankan      html  css  js  c++  java
  • element el-tree 默认选中的节点

    根据接口获取树结构后,设置默认选中的节点,并高亮

    效果图:

     官网中对于这两个节点的解释如下:说实话,刚开始有带你没看懂咋弄!!!

     

     代码如下:

    <el-tree v-loading="loading"
                       :data="treeData"
                       node-key="value"
                       :props="defaultProps"
                       default-expand-all
                       :expand-on-click-node="false"
                       :current-node-key="currentLivingId"
                       ref="popularTree"
                       highlight-current
                       @node-click="nodeClick"
                       :render-content="renderContent">
                <span class="custom-tree-node"
                      slot-scope="{ node, data }">
                  <span>
                    <i :class="data.icon"></i>{{ node.label }}
                  </span>
                </span>
              </el-tree>
    

      

     

     主要就是这两行代码,需要注意的是setCurrentKey函数必须要放到$nextTick里面,要不然tree还未渲染上,是找不到popularTree的

          this.currentLivingId = res.data[0].children[0].value
              this.$nextTick(function () {
                this.$refs.popularTree.setCurrentKey(this.currentLivingId)
          })
  • 相关阅读:
    最舒适的路线(并查集)
    POJ 2411 状态压缩DP
    NYOJ 708 ones
    HUD 1024 Max Sum Plus Plus
    最长上升子序列
    HDU 4717 The Moving Points
    重新开始写随笔
    读书的意义
    读《如何阅读一本书》笔记
    读《GRAY HAT PYTHON》笔记
  • 原文地址:https://www.cnblogs.com/yuerdong/p/15242804.html
Copyright © 2011-2022 走看看