Vue implements tree table through element tree control

Vue implements tree table through element tree control

In Vue, use the element tree control to achieve the effect of tree table

Use indentation to achieve a tree-like effect

Implementation effect diagram

Rendering

Install Dependencies

$ npm install element-plus --save

Element official website

Custom tree controls

Rendering

Analyze the distribution of controls in the diagram. Each parameter has a fixed width . width is used to align the values.

The code mainly uses the renderContent function to customize the tree control

<template>
    <div class="mytree">
          <el-tree
              :data="tree_data"
              :props="defaultProps"
              @node-click="handleNodeClick"
              indent="0"
              :render-content="renderContent"
          ></el-tree>
        </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
export default defineComponent({
    components: {},
    data() {
        return {
              tree_data: [
        {
          // type:1,
          label: 'notice-id1',
                  children: [
                        {
                          label: ['Satellite name code', 'ZOHREH-2'],
                        },
                        {
                          label: ['Organization', 'IRN'],
                        },
                        {
                          label: ['Frequency range', '10950-1450'],
                        },
                        {
                          label: '[upper row] beam name',
                          children: [
                              {
                                  label:['name','RS49'],
                              },
                             {
                                  label:['freq_min','10950'],
                              },
                             {
                                  label:['freq_max','14500'],
                              },
                              {
                                  label:[]'group('+'3'+')','']
                                  children:[
                                     {
                                        label:['10600361','10950','11200','0']
                                     },
                                    {
                                        label:['10600361','10950','11200','0']
                                     },
                                    {
                                        label:['10600361','10950','11200','0']
                                     }
                                  ]
                              }
                      ]
                    },
                  ],
                },
              ],
            defaultProps: {
            children: 'children',
            label: 'label',
          },
        }
    },
    method:{
    // Custom tree control function node represents each node renderContent(h,{node,data,store}){
        //div represents a row of the tree control, and div contains three span tags // Determine the number of label arrays of the node and select the class through ternary operation
        // Set the class to control the alignment of the tree control return h('div',[
          h('span', {class:node.label.length === 2 ? 'nodeStyle':'groupStyle'},node.label[0]),
          h('span', {class:'groupStyle'},node.label[1]),
          h('span',{class:node.label.length === 2 ? 'nodeStyle':'groupStyle'},node.label.length === 2 ? '':node.label[2])
          ]);
    },
    }
})
</script>
<style lang="scss" scoped>
.nodeStyle{
  width:110px;
  display:inline-block;
  text-align:left;
}
.groupStyle{
  width:150px;
  display:inline-block;
  text-align:left;
}
</style>

Other Implementations

Add a dotted line to the element tree control

Element-ui implements adding icons to tree control nodes

Summarize

The tree table is mainly implemented by combining the custom function renderContent of the element's tree control with CSS

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of adding dotted lines to Vue element tree controls
  • Vue Element-ui table realizes tree structure table
  • Vue component library ElementUI implements table loading tree data tutorial
  • Vue+element UI realizes tree table
  • Vue+Element UI tree control integrates drop-down function menu (tree + dropdown +input)
  • Vue Element-ui implements tree control node adding icon detailed explanation

<<:  Display and hide HTML elements through display or visibility

>>:  Solution to CSS anchor positioning being blocked by the top fixed navigation bar

Recommend

Windows10 mysql 8.0.12 non-installation version configuration startup method

This article shares the specific steps for config...

Summary of several key points about mysql init_connect

The role of init_connect init_connect is usually ...

How to deploy Spring Boot using Docker

The development of Docker technology provides a m...

Vue3 AST parser-source code analysis

Table of contents 1. Generate AST abstract syntax...

How to remove MySQL from Ubuntu and reinstall it

First delete mysql: sudo apt-get remove mysql-* T...

Tips for using the docker inspect command

Description and Introduction Docker inspect is a ...

Vue implements book management case

This article example shares the specific code of ...

How to add docker port and get dockerfile

Get the Dockerfile from the Docker image docker h...

Linux method example to view all information of the process

There is a task process on the server. When we us...

Teach you how to deploy Vue project with Docker

1.Write in front: As a lightweight virtualization...

Detailed explanation of where the image pulled by docker is stored

20200804Addendum: The article may be incorrect. Y...