# 数据展示
# 一、表格
参数 | 描述 | 类型 | 默认值 |
---|
columns | 表格列的配置描述 | array | default |
dataSource | 数据数组 | object[] | |
size | 表格大小 | default、middle、small | default |
bordered | 是否展示外边框和列边框 | boolean | false |
scroll | 表格是否可滚动,也可以指定滚动区域的宽、高 | object | |
loading | 页面是否加载中 | boolean、object | false |
showHeader | 是否显示表头 | boolean | true |
headerCell | 个性化头部单元格 | v-slot:headerCell="{title, column}" | |
bodyCell | 个性化单元格 | v-slot:bodyCell="{text, record, index, column}" | |
title | 表格标题 | Function(e)、v-slot:title="title" | |
footer | 表格尾部 | Function(e)、v-slot:footer="footer" | |
# 1、基础表格
<template>
<a-table :dataSource="dataSource" :columns="columns"></a-table>
</template>
<script>
export default {
setup() {
return {
columns: [
{
title: "ID",
dataIndex: "id",
},
{
title: "账号",
dataIndex: "account"
},
{
title: "姓名",
dataIndex: "name"
},
{
title: "QQ号",
dataIndex: "qq"
},
{
title: "性别",
dataIndex: "sex"
},
{
title: "介绍",
dataIndex: "info"
}
],
dataSource: [
{
id: "1",
account: "ouyangke",
name: "欧阳克",
qq: 428188207,
sex: "男",
info: "PHP中文网实战项目组长/专业讲师,擅长WEB项目前后端全栈开发,10年PHP开发经验,曾开发过多个CMS/CRM系统,并负责PHP中文网在线直播系统与学员中心开发!擅长: Vue/Node/PHP/ThinkPHP/Laravel/小程序等项目开发与教学!",
},
{
id: "2",
account: "zhutianpeng",
name: "朱天蓬",
qq: 498668472,
sex: "男",
info: "PHP中文网教学总监/首席讲师教学幽默风趣,讲解由浅入深,具有10多年教学经验,让学员“听得懂,学得会,用得上”是我的至高目标!擅长:ES6/Node/Vue/PHP/ThinkPHP/Laravel开发与教学!",
},
{
id: "3",
account: "meijue",
name: "灭绝师太",
qq: 952637517,
sex: "女",
info: "PHP中文网全栈课程组长/专业讲师8年WEB开发经验,PHP中文网多套畅销课程的作者,既有女老师的耐心,又有男老师的坚毅,深受学员的喜爱,特别是开发新人!擅长: Vue/PHP/ThinkPHP/Laravel/Uni-APP/小程序开发与教学",
}
]
};
}
};
</script>
# 2、Table
属性
<template>
<a-table :dataSource="dataSource" :columns="columns" size="small"></a-table>
<a-table :dataSource="dataSource" :columns="columns" bordered></a-table>
<a-table :dataSource="dataSource" :columns="columns" :scroll="{ x: 2000, y: 100 }"></a-table>
<a-table :dataSource="dataSource" :columns="columns" loading></a-table>
<a-table :dataSource="dataSource" :columns="columns" :showHeader="showHeader"></a-table>
<a-table :dataSource="dataSource" :columns="columns">
<template
{{ title }}
{{ column }}
</template>
<template
{{ text }}
{{ record }}
{{ column }}}
{{ index }}
</template>
<template
<template
</a-table>
</template>
# 3、columns
配置
参数 | 描述 | 类型 | 默认值 |
---|
title | 列头显示文字 | string | |
dataIndex | 列数据在数据项中对应的路径,支持通过数组查询嵌套路径 | string、string[] | |
align | 设置列的对齐方式 | left、right、center | left |
fixed | 列是否固定,可选 true(等效于 left) 'left' 'right' | boolean、string | false |
size | 表格大小 | default、middle、small | default |
key | Vue 需要的 key,如果已经设置了唯一的 dataIndex,可以忽略这个属性 | string | false |
width | 列宽度 | string、number | |
loading | 页面是否加载中 | boolean、object | false |
showHeader | 是否显示表头 | boolean | true |
ellipsis | 超过宽度将自动省略,暂不支持和排序筛选一起使用 | boolean | false |
<template>
<a-table :dataSource="dataSource" :columns="columns" :scroll="{ x: 2000 }"></a-table>
</template>
<script>
export default {
setup() {
return {
columns: [
{
title: "ID",
dataIndex: "id",
fixed: true,
align: 'center',
key : "id",
width: '100px',
},
{
title: "账号",
dataIndex: "account",
},
{
title: "姓名",
dataIndex: "name"
},
{
title: "QQ号",
dataIndex: "qq"
},
{
title: "性别",
dataIndex: "sex"
},
{
title: "介绍",
dataIndex: "info",
fixed: 'right',
ellipsis: true
}
]
};
},
};
</script>
参数 | 描述 | 类型 | 默认值 |
---|
position | 指定分页显示的位置, 取值为topLeft、topCenter、topRight、bottomLeft、 bottomCenter、bottomRight | Array | [bottomRight] |
total | 数据总数 | number | 0 |
current(v-model) | 当前页数 | number | |
pageSize(v-model) | 每页条数 | number | |
hideOnSinglePage | 只有一页时是否隐藏分页器 | boolean | false |
pageSizeOptions | 指定每页可以显示多少条 | string[] | ['10', '20', '30', '40'] |
size | 当为「small」时,是小尺寸分页 | string | |
disabled | 禁用分页 | boolean | |
<template>
<a-table
:columns="columns"
:dataSource="dataSource"
:pagination="{position: ['topCenter'],pageSize: 10,disabled:true,size:'small'}"
/>
</template>
<script>
export default {
setup() {
const columns = [
{
title: "ID",
dataIndex: "id"
},
{
title: "账号",
dataIndex: "account"
},
{
title: "姓名",
dataIndex: "name"
},
{
title: "介绍",
dataIndex: "info"
}
];
const dataSource = [...Array(100)].map((_, i) => ({
id: i,
account: `jiangshi${i}`,
name: `讲师${i}`,
info: `php中文网讲师,编号: ${i}`
}));
return {
columns,
dataSource
}
}
};
</script>
# 5、rowSelection
选择功能
参数 | 描述 | 类型 | 默认值 |
---|
type | 多选/单选,checkbox or radio | string | checkbox |
dataSource | 数据数组 | object[] | |
columnWidth | 自定义列表选择框宽度 | string、number | |
columnTitle | 自定义列表选择框标题 | string、VNode | |
selections | 自定义选择项 配置项, 设为 true 时使用默认选择项 | object[]、boolean | true |
fixed | 把选择框列固定在左边 | boolean | true |
<template>
<a-table
:columns="columns"
:dataSource="dataSource"
:scroll="{ x: 2000 }"
:rowSelection="{
type: 'checkbox',
columnWidth: 200,
columnTitle: '标题',
selections: true,
fixed: true
}"
/>
</template>
<script>
export default {
setup() {
const columns = [
{
title: "ID",
dataIndex: "id"
},
{
title: "账号",
dataIndex: "account"
},
{
title: "姓名",
dataIndex: "name"
},
{
title: "介绍",
dataIndex: "info"
}
];
const dataSource = [...Array(100)].map((_, i) => ({
key: i,
id: i,
account: `jiangshi${i}`,
name: `讲师${i}`,
info: `php中文网讲师,编号: ${i}`
}));
return {
columns,
dataSource
}
}
};
</script>
事件名称 | 描述 | 回调参数 |
---|
change | 选中项发生变化时的回调 | Function(selectedRowKeys, selectedRows) |
<template>
<a-table
:columns="columns"
:dataSource="dataSource"
:rowSelection="rowSelection"
/>
</template>
<script>
export default {
setup() {
const columns = [
{
title: "ID",
dataIndex: "id"
},
{
title: "账号",
dataIndex: "account"
},
{
title: "姓名",
dataIndex: "name"
},
{
title: "介绍",
dataIndex: "info"
}
];
const dataSource = [...Array(100)].map((_, i) => ({
key: i,
id: i,
account: `jiangshi${i}`,
name: `讲师${i}`,
info: `php中文网讲师,编号: ${i}`
}));
const rowSelection = {
onChange(selectedRowKeys, selectedRows) {
console.log(selectedRowKeys, selectedRows);
}
};
return {
columns,
dataSource,
rowSelection,
};
}
};
</script>