el-tree带指定图标动态加载

 

效果图 

 

 <el-tree
    :load="loadFolder"
    ref="tree"
    node-key="data_id"
    :props="{children: 'children',label: 'name',isLeaf: 'leaf'}"
    show-checkbox
    @check-change="handleCheckChange"
    empty-text = "正在获取数据">
    <span class="custom-tree-node" slot-scope="{node,data}" >
    <i :class="data.icon" style="color: #2482ED;"></i>
    <span :style="data.source !== 0?'':'font-weight: 600;'">{{ data.name }}</span>
    </span>
</el-tree>

 js方法

    loadFolder (node, resolve) { // 获取文件夹列表,动态加载
      let id = node.data ? node.data.data_id : ''
      this.$store.dispatch('list_tree', { id: id }).then(res => {
        for (let iterator of res.data.data) {
          if (iterator.name.includes('全国')) { // 将过长的数据切割重复的部分
            iterator.name = iterator.name.slice(13)
          }
          if (iterator.source !== 0) {
            iterator.leaf = true
            iterator.icon = 'el-icon-tickets'// 文件图标
          } else {
            iterator.disabled = true
            iterator.icon = 'el-icon-folder'// 文件夹图标
          }
        }
        resolve(res.data.data)
      })
    },
    handleCheckChange (data, checked, indeterminate) { // 匹配数据多选
       if (checked) {
        if (data.source !== 0) {
          this.tempData.push(data)
        }
      } else {
        this.tempData.forEach((ele, index) => {
          if (ele.data_id === data.data_id) {
            this.tempData.splice(index, 1) // 根据下标删除不需要的对象
          }
        })
      }
    },

 对于特定节点不显示图标

.tree{
  /deep/ .el-tree-node {//不显示文件夹节点
    .is-leaf + .el-checkbox .el-checkbox__inner {
     //在CSS中“+”符号选择器被称为相邻兄弟选择器,用于选取在同一父元素下的
//,紧跟指定元素之后的另一个元素。
        display:inline-block;
    }
    .el-checkbox__input> .el-checkbox__inner {
        display:none;
    }
  }
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值