Vue3 table表格組件的使用
一、Ant Design Vue
在大量數(shù)據(jù)需要展示時(shí),我們一般都會(huì)以報(bào)表的形式展現(xiàn),按照直覺習(xí)慣,肯定使用table表格來展示行列數(shù)據(jù)。
因此,我們要使用Ant Design Vue組件庫中的table組件,來進(jìn)行數(shù)據(jù)的綁定。
1、官網(wǎng)地址
官網(wǎng)地址:https://2x.antdv.com/components/table-cn#API
2、怎么使用
我們先對(duì)電子書管理頁面改造,將布局進(jìn)行調(diào)整,
示例代碼如下:
<template>
<a-layout class="layout">
<a-layout-content
:style="{ background: '#fff', padding: '24px', minHeight: '280px' }">
<div class="about">
<h1>電子書管理頁面</h1>
</div>
</a-layout-content>
</a-layout>
</template>
效果如下:

3、將電子書表格進(jìn)行展示
要做的事:
- 表格渲染
slots: 自定義渲染title: 表頭渲染customRender: 值渲染
示例代碼如下:
<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)">
編輯
</a-button>
<a-button type="danger">
刪除
</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: '封面',
dataIndex: 'cover',
slots: {customRender: 'cover'}
},
{
title: '名稱',
dataIndex: 'name'
},
{
title: '分類一',
dataIndex: 'category1Id',
key: 'category1Id',
},
{
title: '分類二',
dataIndex: 'category2Id',
key: 'category2Id',
},
{
title: '文檔數(shù)',
dataIndex: 'docCount'
},
{
title: '閱讀數(shù)',
dataIndex: 'viewCount'
},
{
title: '點(diǎn)贊數(shù)',
dataIndex: 'voteCount'
},
{
title: 'Action',
key: 'action',
slots: {customRender: 'action'}
}
];
//使用ref進(jìn)行數(shù)據(jù)綁定
const ebooks = ref();
// 使用reactive進(jìn)行數(shù)據(jù)綁定
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>
實(shí)際效果:

二、總結(jié)
對(duì)于table組件的使用不是很熟的話,需要不斷去嘗試,簡(jiǎn)單說,就是對(duì)象屬性的映射。
總體感覺下來,還是進(jìn)行數(shù)據(jù)綁定后,在進(jìn)行頁面展示,如不是很清晰,請(qǐng)參考這篇《Vue3 列表界面數(shù)據(jù)展示詳情》文章。
到此這篇關(guān)于Vue3 table表格組件的使用的文章就介紹到這了,更多相關(guān)Vue3 table表格組件內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue項(xiàng)目中實(shí)現(xiàn)緩存的最佳方案詳解
這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目中實(shí)現(xiàn)緩存的最佳方案,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
手把手教你寫一個(gè)vue全局注冊(cè)的Toast的實(shí)現(xiàn)
本文主要介紹了手把手教你寫一個(gè)vue全局注冊(cè)的Toast的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
VUE DEMO之模擬登錄個(gè)人中心頁面之間數(shù)據(jù)傳值實(shí)例
今天小編就為大家分享一篇VUE DEMO之模擬登錄個(gè)人中心頁面之間數(shù)據(jù)傳值實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10
vue-router2.0 組件之間傳參及獲取動(dòng)態(tài)參數(shù)的方法
下面小編就為大家?guī)硪黄獀ue-router2.0 組件之間傳參及獲取動(dòng)態(tài)參數(shù)的方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11
vite(vue3)配置內(nèi)網(wǎng)ip訪問的方法步驟
Vite是一個(gè)快速的構(gòu)建工具,Vue3是一個(gè)流行的JavaScript框架,下面這篇文章主要給大家介紹了關(guān)于vite(vue3)配置內(nèi)網(wǎng)ip訪問的方法步驟,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下2023-05-05

