antd?vue?table表格內(nèi)容如何格式化
更新時間:2022年01月24日 09:59:31 作者:狗狗狗狗亮
這篇文章主要介紹了antd?vue?table表格內(nèi)容如何格式化,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
antd vue table表格內(nèi)容格式化
目前在學(xué)習(xí)使用ant-design-vue,遇到table內(nèi)容需要格式化
如下面的性別和打印狀態(tài)

操作如下
columns中
{
title: "性別",
dataIndex: "sex",
align: "center",
width: 80,
scopedSlots: { customRender: "sex" }
},
{
title: "打印狀態(tài)",
dataIndex: "status",
align: "center",
scopedSlots: { customRender: "status" }
}
template中
<a-table
bordered
:rowSelection="rowSelection"
:columns="columns"
:dataSource="data"
rowKey="id"
:customRow="Rowclick"
:pagination="pagination"
:scroll="{ y: 520 }"
size="small"
>
<span slot="sex" slot-scope="sex">
{{ sex == 1 ? "男" : sex == 0 ? "女" : "/" }}
</span>
<span slot="status" slot-scope="status">
{{ status == 1 ? "已打印" : "未打印" }}
</span>
</a-table>
轉(zhuǎn)換后

antd table表格組件基本使用
第一次使用antd的table表格組件
借用官方文檔數(shù)據(jù),展示下Demo
import React from 'react';
import { Table } from 'antd';
const columns = [
{
title: 'Name',
dataIndex: 'name',
render: text => <a>{text}</a>,
},
{
title: 'Age',
dataIndex: 'age',
},
{
title: 'Address',
dataIndex: 'address',
},
];
const data = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sidney No. 1 Lake Park',
},
{
key: '4',
name: 'Disabled User',
age: 99,
address: 'Sidney No. 1 Lake Park',
},
];
export default class Basic extends React.Component{
render(){
const rowSelection = {
onChange: (selectedRowKeys, selectedRows) => {
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
},
getCheckboxProps: record => ({
disabled: record.name === 'Disabled User', // Column configuration not to be checked
name: record.name,
}),
};
return (
<div>
<Table rowSelection={rowSelection} columns={columns} dataSource={data} />
</div>
);
}
}
效果如下

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用vue-router設(shè)置每個頁面的title方法
下面小編就為大家分享一篇使用vue-router設(shè)置每個頁面的title方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-02-02
vue router嵌套路由在history模式下刷新無法渲染頁面問題的解決方法
這篇文章主要介紹了vue router嵌套路由在history模式下刷新無法渲染頁面問題的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01

