Elementui tree Custom Node Icon

you can only define two-level node icons through css, as shown in the following figure

clipboard.png

hope to achieve the purpose of displaying different icons on different nodes, ask for guidance

Mar.28,2021

<template>
    <el-tree
        :data="treeData"
        :expand-on-click-node="true"
        class="project-tree"
        unselectable="on"
        :render-content="renderContent"
    >
</template>
<script>
export default{
    methods: {
        renderContent(h, { node, data, store }) {
            return (
              <span class="custom-tree-node">
                <i class={data.className}></i>
                <span style="margin-left:5px;">{node.label}</span>
              </span>
              );
          }
  }
}
<script>
<style>
i{
    display:inline-block;
    background:url("...")
}
</style>

data:

"treeData": [
      {
      "id": 1,
      "label": "haha",
      "className": "first-level",
      "children": [
          {
          "id": 11,
          "label": "hehe",
          "className": "second-level",
          "children": [
                  {
                      "id": 111,
                      "className": "third-level",
                      "label": "heihei"
                  }
              ]
          }
        ]
     }
 ]

there is an idea you can refer to, feasible:

  • hide the default triangle icon through css
  • render-content customize node data. At this point, you can customize the icon you want
  • .

I mistook this for NaNmenu! So sorry.

Why use background?
just use the I tag directly.

clipboard.png

customize the icon with iconMoon, just define it like this.

http://element.eleme.io/-sharp/zh-.


can be rendered through the custom rendering method provided, in which any component can be customized

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b40434-2c4f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b40434-2c4f4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?