Ant Design Vue中Table对齐方式显示省略号
<template>
<!-- bordered 表示表格中的边框
pagination="false"不要分页
-->
<a-table :data-source="dataSource" :columns="columns" :pagination="false">
<template #operation="{ record }">
<a class="">编辑</a>
<a class="line-linela"></a>
<a-popconfirm
v-if="dataSource.length"
title="Sure to delete?"
@confirm="onDelete(record.key)"
>
<a>删除</a>
</a-popconfirm>
</template>
</a-table>
</template>
<script lang="ts">
import { defineComponent, Ref, ref } from 'vue'
interface DataItem {
key: string
fileNmae: string
age: string
address: string
}
export default defineComponent({
setup() {
// 字段(也就是表头)
const columns = [
{
title: '编号', //字段名称
dataIndex: 'fileNmae',
'30%',
},
{
title: '名称',
dataIndex: 'fileNmae',
},
{
title: '备注',
dataIndex: 'address',
ellipsis: true, //超出显示省略好
},
{
title: '操作',
dataIndex: 'operation',
slots: { customRender: 'operation' },
align: 'right', //左对齐
},
]
// 表中的数据
const dataSource: Ref<DataItem[]> = ref([
{
key: '0',
fileNmae: 'ML2340124',
age: '耳机目录',
address: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
},
{
key: '1',
fileNmae: 'Edward King 1',
age: '耳机目录',
address: 'London, Park Lane no. 1',
},
])
const onDelete = (key: string) => {
console.log('==>', dataSource)
dataSource.value = dataSource.value.filter(item => item.key !== key)
}
return {
columns,
onDelete,
dataSource,
}
},
})
</script>
<style lang="less">
.line-linela {
1px;
height: 13px;
display: inline-block;
background: #f0f0f0 !important;
margin-left: 8px;
margin-right: 9px;
}
</style>