Analysis of the ideas of implementing vertical tables in two ways in Vue project

Analysis of the ideas of implementing vertical tables in two ways in Vue project

Problem Description

In our projects, horizontal tables are common, but sometimes we also make vertical tables due to needs. For example, the vertical table below:

When we see such a rendering, the first thing that comes to our mind is to use the UI framework and make some changes to solve the problem. However, Ele.me UI does not directly provide such an example. Some students may want to use the el-table in Ele.me UI to merge rows and columns to achieve this. In fact, if you do this, it will be troublesome. For example, the following merged rows and columns:

For renderings like this, you don’t necessarily have to use UI components. Sometimes you can use native methods to do it. On the contrary, it will be more convenient. This article introduces two ways to implement such a simple vertical table. The actual scenario may be more complicated, but as I said, as long as you have an idea, it is not a big problem. The key to programming is thinking:

Method 1 (native method) is not recommended

The idea is: draw the table style yourself, and use floating to arrange them from left to right

<template>
  <div id="app">
    <ul class="proWrap">
      <template v-for="(item, index) in data">
        <li class="proItem" :key="index">
          <span>{{ item.title }}</span>
          <span>{{ item.value == "" ? "To be completed" : item.value }}</span>
        </li>
      </template>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      data: [
        {
          title: "Importance Level",
          value: "666",
        },
        {
          title: "Pre-sale status",
          value: "666",
        },
        {
          title: "Cooperation Status",
          value: "",
        },
        {
          title: "Pre-sale status",
          value: "",
        },
        {
          title: "Technical Agreement Status",
          value: "",
        },
        {
          title: "Winning Bidder",
          value: "",
        },
        {
          title: "Cooperation Status",
          value: "",
        },
        {
          title: "Cooperation feedback time",
          value: "",
        },
      ],
    };
  },
  methods: {},
};
</script>

<style lang="less" scoped>
#app {
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  padding: 50px;
  .proWrap {
    width: 100%;
    border: 1px solid #e9e9e9;
    border-right: 0;
    border-bottom: 0;
    // How many groups are placed in each row? Here we divide by a certain number.proItem {
      width: 100% / 3;
      float: left; // float to the left,
      span {
        display: inline-block;
        width: calc(50% - 2px);
        height: 50px;
        line-height: 50px;
        text-align: center;
        border-right: 1px solid #e9e9e9;
        border-bottom: 1px solid #e9e9e9;
      }
      span:nth-child(1) {
        background: #fafafa;
      }
    }
    // Clear the float. Failure to do so will cause the leftmost border to disappear&::after {
      content: "";
      display: block;
      clear: both;
    }
  }
}
// Remove the default style of li {
  list-style-type: none;
}
</style>

Method 2 (using grid layout components) is recommended

It is more convenient to use the grid system that comes with Ele.me. We can set the number of groups that appear in each line by controlling the :span attribute of el-col. If there are more groups, they will automatically wrap. As for the style of the table, we can set it ourselves. This method is very simple. Code attached:

<template>
  <div id="app">
    <el-col :span="howWidth" v-for="(item, index) in tableArr" :key="index">
      <div class="box">
        <div class="content1">{{ item.key }}</div>
        <div class="content2">{{ item.value == "" ? "To be completed" : item.value }}</div>
      </div>
    </el-col>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableArr: [
        {
          key: "Name",
          value: "Sun Wukong",
        },
        {
          key: "age",
          value: 500,
        },
        {
          key: "Height",
          value: "As high as a mountain",
        },
        {
          key: "gender",
          value: "Male",
        },
        {
          key: "address",
          value: "Water Curtain Cave in Huaguo Mountain",
        },
        {
          key: "Education",
          value: "Tian Ting Bi Ma Wen's Educational Background",
        },
        {
          key: "capability",
          value: "Strong",
        },
        {
          key: "nickname",
          value: "The Great Sage",
        },
      ],
      howWidth: 8,
    };
  },
  methods: {},
};
</script>

<style lang="less" scoped>
#app {
  width: 100%;
  min-height: 100vh;
  box-sizing: border-box;
  padding: 50px;
  .box {
    width: 100%;
    height: 40px;
    display: flex;
    border-left: 1px solid #e9e9e9;
    border-top: 1px solid #e9e9e9;
    .content1 {
      width: 40%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      background-color: #fafafa;
      border-right: 1px solid #e9e9e9;
      border-bottom: 1px solid #e9e9e9;
      color: #333;
      font-size: 14px;
    }
    .content2 {
      width: 60%;
      height: 40px;
      line-height: 40px;
      text-align: center;
      background-color: #fff;
      border-right: 1px solid #e9e9e9;
      border-bottom: 1px solid #e9e9e9;
      color: #b0b0b2;
      font-size: 14px;
    }
  }
}
</style>

This concludes this article about the analysis of two ways to implement vertical tables in Vue projects. For more relevant Vue vertical table content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Vue+Element Custom Vertical Table Header Tutorial

<<:  Steps to deploy hyper-V to achieve desktop virtualization (graphic tutorial)

>>:  vmware workstation12 installation centos prompts VMware Player and Device/Credential Guard are incompatible, reasons and solutions

Recommend

How to quickly build an FTP file service using FileZilla

In order to facilitate the storage and access of ...

Analysis of Linux boot system methods

This article describes how to boot the Linux syst...

JavaScript ES6 Module Detailed Explanation

Table of contents 0. What is Module 1.Module load...

Docker solves the problem that the terminal cannot input Chinese

Preface: One day, I built a MySQL service in Dock...

Use crontab to run the script of executing jar program regularly in centOS6

1. Write a simple Java program public class tests...

Detailed process of installing various software in Docker under Windows

1. Install MySQL # Download mysql in docker docke...

Several ways to improve the readability of web pages

1. Use contrasting colours. The contrast here ref...

MySQL DeadLock troubleshooting full process record

【author】 Liu Bo: Senior Database Manager at Ctrip...

Solution to the problem that the docker container cannot be stopped

The solution is as follows: 1. Force delete conta...

CSS style reset and clear (to make different browsers display the same effect)

In order to make the page display consistent betwe...

HTML Grammar Encyclopedia_HTML Language Grammar Encyclopedia (Must Read)

Volume Label, Property Name, Description 002 <...

CSS animation property usage and example code (transition/transform/animation)

During development, a good user interface will al...

Detailed explanation of MySQL index principles and optimization

Preface This article was written by a big shot fr...

What is ZFS? Reasons to use ZFS and its features

History of ZFS The Z File System (ZFS) was develo...