Use of Vue3 table component

Use of Vue3 table component

1. Ant Design Vue

When a large amount of data needs to be displayed, we usually present it in the form of a report. According to intuitive habits, we must use table to display row and column data.

Therefore, we need to use table component in the Ant Design Vue component library to bind the data.

1. Official website address

Official website address: https://2x.antdv.com/components/table-cn#API

2. How to use

We first remodeled the e-book management page and adjusted the layout.

The sample code is as follows:

<template>
  <a-layout class="layout">
    <a-layout-content
        :style="{ background: '#fff', padding: '24px', minHeight: '280px' }">
      <div class="about">
        <h1>E-book management page</h1>
      </div>
    </a-layout-content>
  </a-layout>

 
</template>

The effect is as follows:

3. Display the e-book table

Things to do:

  • Table Rendering
  • slots : custom rendering
  • title : header rendering
  • customRender : value rendering

The sample code is as follows:

<template>
  <a-layout class="layout">
    <a-layout-content
        :style="{ background: '#fff', padding: '24px', minHeight: '280px' }">
      <a-table :columns="columns"
               :data-source="ebooks1"
               :pagination="pagination"
               :loading="loading"
      >
        <template #cover="{ text: cover }">
          <img v-if="cover" :src="cover" alt="avatar"/>
        </template>
        <template #name="{ text: name }">
          <a>{{ text }}</a>
        </template>
        <template #customTitle>

      <span>
        <smile-outlined/>
        Name
      </span>
          </template>
          <template #action="{ record }">
      <span>
        <a-space size="small">
            <a-button type="primary" @click="edit(record)">
              Edit</a-button>
             <a-button type="danger">
                Delete</a-button>
          </a-space>
      </span>
          </template>
      </a-table>
    </a-layout-content>
  </a-layout>

</template>
<script lang="ts">
import {SmileOutlined, DownOutlined} from '@ant-design/icons-vue';
import {defineComponent, onMounted, reactive, ref, toRef} from 'vue';
import axios from 'axios';

export default defineComponent({
  name: 'AdminEbook',
  setup() {
    const pagination = {
      onChange: (page: number) => {
        console.log(page);
      },
      pageSize: 3,
    };

    const loading = ref(false);
    const columns = [
      {
        title: 'Cover',
        dataIndex: 'cover',
        slots: {customRender: 'cover'}
      },
      {
        title: 'Name',
        dataIndex: 'name'
      },
      {
        title: 'Classification 1',
        dataIndex: 'category1Id',
        key: 'category1Id',
      },
      {
        title: 'Classification 2',
        dataIndex: 'category2Id',
        key: 'category2Id',
      },
      {
        title: 'Number of documents',
        dataIndex: 'docCount'
      },
      {
        title: 'Reading Number',
        dataIndex: 'viewCount'
      },
      {
        title: 'Number of Likes',
        dataIndex: 'voteCount'
      },
      {
        title: 'Action',
        key: 'action',
        slots: {customRender: 'action'}
      }
    ];
    //Use ref for data binding const ebooks = ref();
    // Use reactive data binding const ebooks1 = reactive({books: []})
    onMounted(() => {
      axios.get("/ebook/list?name=").then(response => {
        const data = response.data;
        ebooks.value = data.content;
        ebooks1.books = data.content;
      })
    })
    return {
      pagination,
      loading,
      columns,
      ebooks1: ebooks,
      ebooks2: toRef(ebooks1, "books")
    }
  },
  components:
    SmileOutlined,
    DownOutlined,
  },
});
</script>
<style scoped>
img {
  width: 50px;
  height: 50px;
}
</style>

Actual effect:

2. Conclusion

If you are not familiar with the use of table components, you need to keep trying. Simply put, it is the mapping of object properties.

In general, it is better to bind the data before displaying the page. If it is not very clear, please refer to this article "Details of Vue3 list interface data display".

This is the end of this article about the use of Vue3 table components. For more relevant Vue3 table component content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to encapsulate the table component of Vue Element
  • Detailed example of encapsulating the table component of Vue Element
  • vxe-table vue table table component function
  • Vue.js implements a sortable table component function example
  • Detailed example of implementing a simple table component in Vue
  • Vue fixed header fixed column click table header sortable table component
  • Detailed example of developing Vue.js table component
  • Vue+elementui realizes multiple selection and search functions of drop-down table
  • The table in vue+Element is editable (select drop-down box)
  • Vue implements drop-down table component

<<:  How to implement controllable dotted line with CSS

>>:  Summary of MySQL 8.0 Online DDL Quick Column Addition

Recommend

WeChat Mini Program Basic Tutorial: Use of Echart

Preface Let’s take a look at the final effect fir...

Mysql method to copy a column of data in one table to a column in another table

mysql copy one table column to another table Some...

Abbreviation of HTML DOCTYPE

If your DOCTYPE is as follows: Copy code The code ...

React-native sample code to implement the shopping cart sliding deletion effect

Basically all e-commerce projects have the functi...

Vue uses better-scroll to achieve horizontal scrolling method example

1. Implementation principle of scrolling The scro...

Detailed explanation of two points to note in vue3: setup

Table of contents In vue2 In vue3 Notes on setup ...

Example of using CSS3 to achieve shiny font effect when unlocking an Apple phone

0. Introduction August 18, 2016 Today, I noticed ...

Detailed steps to install Docker mongoDB 4.2.1 and collect springboot logs

1: Install mongodb in docker Step 1: Install mong...

Detailed explanation of HTML page header code example

Knowledge point 1: Set the base URL of the web pa...

Detailed tutorial on MySQL installation and configuration

Table of contents Installation-free version of My...

Solve the problem that IN subquery in MySQL will cause the index to be unusable

Today I saw a case study on MySQL IN subquery opt...

How to obtain a permanent free SSL certificate from Let's Encrypt in Docker

1. Cause The official cerbot is too annoying. It ...

Steps to purchase a cloud server and install the Pagoda Panel on Alibaba Cloud

Alibaba Cloud purchases servers Purchase a cloud ...

Vue routing lazy loading details

Table of contents 1. What is lazy loading of rout...