我们知道使用一个Table进行数组数据的展示,需要定义columns,然后再传入进行展示:
import React from 'react';
import { Table } from 'antd';
// 模拟数据数组
const dataSource = [
{
key: '1',
name: '胡彦斌',
age: 32,
address: '西湖区湖底公园1号'
},
{
key: '2',
name: '胡彦祖',
age: 42,
address: '西湖区湖底公园2号'
}
];
// 列定义
const columns = [
{
title: '姓名',
dataIndex: 'name',
key: 'name'
},
{
title: '年龄',
dataIndex: 'age',
key: 'age'
},
{
title: '地址',
dataIndex: 'address',
key: 'address'
}
];
const App = () => {
return <Table dataSource={dataSource} columns={columns} />;
};
export default App;
请问是否有更加方便的组件呢(我们传入datasource,直接就进行展示)?
如果你使用的是 vue 的话,可以使用 vuetify 组件库的 v-data-table 组件:
在线体验:Vuetify Play
如果你使用的是 react 的话,可以使用 antd 的 table 组件