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 recommendedThe 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 recommendedIt 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:
|
<<: Steps to deploy hyper-V to achieve desktop virtualization (graphic tutorial)
Because I wrote the word transition incorrectly i...
Two implementations of Vue drop-down list The fir...
CSS3 Patterns Gallery This CSS3 pattern library s...
Sprites: In the past, each image resource was an ...
Table of contents transition hook function Custom...
In the process of Django web development, when wr...
MySQL group sorting to find the top N Table Struc...
Students who use Ansible know that Ansible only s...
Preface: The storage engine is the core of the da...
The bash history command in Linux system helps to...
Many people also asked me what books I read when ...
Table of contents cycle for for-in for-of while d...
Mainly discuss its structure and some important pr...
background When developing a feature similar to c...
Environment: MacOS_Cetalina_10.15.1, Mysql8.0.18,...