el-table 的slot怎么使用
el-table 的 slot 可以用来自定义表格的显示内容和样式。以下是一些常用的 slot:
header:表头 slot,用来自定义表格的表头内容和样式。default:默认 slot,用来自定义表格的数据行内容和样式。summary:汇总行 slot,用来自定义表格的汇总行内容和样式。expand:展开行 slot,用来自定义表格的展开行内容和样式。
使用方法如下:
<el-table :data="tableData">
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
<el-table-column prop="gender" label="性别"></el-table-column>
<template slot="header">
<th>自定义表头</th>
</template>
<template slot-scope="{ row }" slot="default">
<td>{{ row.name }}</td>
<td>{{ row.age }}</td>
<td>{{ row.gender }}</td>
</template>
<template slot="summary">
<td>汇总</td>
<td>{{ tableData.reduce((total, item) => total + item.age, 0) }}</td>
<td></td>
</template>
<template slot-scope="{ row }" slot="expand">
<p>这是展开行内容:{{ row.desc }}</p>
</template>
</el-table>
在上面的例子中,我们使用了四个 slot 来自定义表格的显示内容和样式。其中,header slot 用来自定义表头,default slot 用来自定义数据行,summary slot 用来自定义汇总行,expand slot 用来自定义展开行。我们可以在每个 slot 的模板中使用 slot-scope 来访问当前行的数据。
原文地址: https://www.cveoy.top/t/topic/bygQ 著作权归作者所有。请勿转载和采集!