官方例子沒有體現出來slot的最佳用法
<template>
<a-table :columns="columns" :data-source="data">
<span slot="tags" slot-scope="tags">
<a-tag v-for="tag in tags" :key="tag">
{{ tag.toUpperCase() }}
</a-tag>
</span>
</a-table>
</template>
<script>
const columns = [
{
title: 'Tags',
key: 'tags',
dataIndex: 'tags',
scopedSlots: { customRender: 'tags' },
},
];
</script>
- 問題1:
slot-scope已經廢棄,不論是volar還是vue2.7都不是很兼容 - 問題2:官方例子columns配置和表格分離,語義化不是很好
環境
- ant-design-vue:
1.7.8 - vue:
2.7 - volar
最佳實踐
<a-table size="small" bordered :loading="loading" :dataSource="dataSource" :pagination="false" rowKey="group">
<a-table-column title="分組" dataIndex="group" width="120px" />
<a-table-column title="關卡數量" dataIndex="count" width="100px" />
<a-table-column title="創建時間" dataIndex="createTime" width="165px">
<template #customRender="timestamp">{{ datetime(timestamp) }}</template>
</a-table-column>
<a-table-column title="創建人" dataIndex="sso" width="100px" />
<a-table-column title="操作" dataIndex="op" width="160px">
<template #customRender="noused, record">
<a-button size="small" @click="onShowLevelModal(record.group)">編輯關卡映射表</a-button>
</template>
</a-table-column>
</a-table>
以上寫法
- 支持
v-slot用法, columns配置更加統一
完