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

Detailed explanation of the use of the <meta> tag in HTML

In the web pages we make, if we want more people ...

Web Design Experience: 5 Excellent Web Design Concepts Full Analysis (Pictures)

Unlike other types of design, web design has been ...

Use of Linux ipcs command

1. Command Introduction The ipcs command is used ...

Docker container operation instructions summary and detailed explanation

1. Create and run a container docker run -it --rm...

A brief discussion on the performance issues of MySQL paging limit

MySQL paging queries are usually implemented thro...

MySQL 8.0.20 winx64 installation and configuration method graphic tutorial

This article shares with you the installation and...

HTML left and right layout example code

CSS: Copy code The code is as follows: html,body{ ...

Essential Handbook for Web Design 216 Web Safe Colors

The color presentation on a web page will be affec...

Detailed explanation of the problem of configuring servlet url-pattern in tomcat

When configuring web.xml for tomcat, servlet is a...

Analysis of pitfalls in rounding operation of ROUND function in MySQL

This article uses examples to illustrate the pitf...

How to create a trigger in MySQL

This article example shares the specific code for...

Detailed example of MySQL data storage process parameters

There are three types of MySQL stored procedure p...

Windows10 mysql 8.0.12 non-installation version configuration startup method

This article shares the specific steps for config...

How to monitor oracle database using zabbix agent2

Overview In zabbix version 5.0 and above, a new f...