zoukankan      html  css  js  c++  java
  • el-tree踩坑记

    有一个需求是要给el-tree组件中的节点后面添加一个从后台获取的数据。
    代码如下:

    <el-col :span="6">
                <el-tree 
                      class="treeitems"
                      :data="depts"
                      node-key="code"
                      :props="defaultProps" 
                      :highlight-current="true"
                      
                      :default-expanded-keys="[0]"
                      auto-expand-parent
                      :expand-on-click-node = "false"
                      ref="tree"
                  >
                </el-tree>
              </el-col>
    defaultProps: {
              label: 'name',
              children: 'children',
     },
    默认情况下,只显示name的值。
     
    如果这样添加
    <el-tree 
                      class="treeitems"
                      :data="depts"
                      node-key="code"
                      :props="defaultProps" 
                      :highlight-current="true"
                      
                      :default-expanded-keys="[0]"
                      auto-expand-parent
                      :expand-on-click-node = "false"
                      ref="tree"
                  >
                  <span class="custom-tree-node" slot-scope="{ node,data }">
                      <span>{{data.count}}</span>
                  </span>
                </el-tree>
    只显示data.count的值,就会把name的值给覆盖掉。

    所以要完成需求,这样添加:
    <el-tree 
                      class="treeitems"
                      :data="depts"
                      node-key="code"
                      :props="defaultProps" 
                      :highlight-current="true"
                      
                      :default-expanded-keys="[0]"
                      auto-expand-parent
                      :expand-on-click-node = "false"
                      ref="tree"
                  >
                  <span class="custom-tree-node" slot-scope="{ node,data }">
                       <span>{{node.label}}</span> 
                      <span>{{data.count}}</span>
                  </span>
                </el-tree>
    才可以满足需求!

    defaultProps: {
              label: 'name',
              children: 'children',
            },

    键值是label,children 不可变,label是要显示的值!


  • 相关阅读:
    JS中使用正则表达式封装的一些常用的格式验证的方法-是否外部url、是否小写、邮箱格式、是否字符、是否数组
    Java中操作字符串的工具类-判空、截取、格式化、转换驼峰、转集合和list、是否包含
    Cocos2d-x 2.0 自适应多种分辨率
    应用自定义移动设备外观
    为移动设备应用程序创建外观
    【2020-11-28】人生十三信条
    【2020-11-27】事实证明,逃避是下等策略
    Python 之web动态服务器
    Python 之pygame飞机游戏
    PHP 之转换excel表格中的经纬度
  • 原文地址:https://www.cnblogs.com/xingzoudecd/p/14029457.html
Copyright © 2011-2022 走看看