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

A few things you need to know about responsive layout

1. Introduction Responsive Web design allows a we...

Sample code for batch deployment of Nginx with Ansible

1.1 Copy the nginx installation package and insta...

Hello dialog box design experience sharing

"What's wrong?" Unless you are accus...

Explanation of the concept and usage of Like in MySQL

Like means "like" in Chinese, but when ...

Troubleshooting of master-slave delay issues when upgrading MySQL 5.6 to 5.7

Recently, when upgrading the Zabbix database from...

Detailed explanation of MySQL delayed replication library method

Simply put, delayed replication is to set a fixed...

Getting Started with Mysql--sql execution process

Table of contents 1. Process 2. Core Architecture...

MySQL and MySQL Workbench Installation Tutorial under Ubuntu

Ubuntu install jdk: [link] Install Eclipse on Ubu...

A quick review of CSS3 pseudo-class selectors

Preface If CSS is the basic skill of front-end de...

MySQL 8.0.23 installation and configuration method graphic tutorial under win10

This article shares the installation and configur...

Several ways to encrypt and decrypt MySQL (summary)

Table of contents Written in front Two-way encryp...