依赖 element-ui typescript
npm i ele-span-method
import { eleSpanMethod } from 'ele-span-method'
<el-table :data="data" :span-method="eleSpanMethod(data,['id','name'],['name'])">
</el-table>
<T extends object,K extends keyof T>(list:T[],primaryKey:K[],mergeKey?:K[]) => {}
list可以是不需要经过排序,任意顺序的,指定了 primaryKey 的字段,会经过分组排序 例如
[
{id:'1',name:'A1',age:10},
{id:'2',name:'A2',age:20},
{id:'1',name:'A3',age:30},
{id:'4',name:'A4',age:40},
{id:'1',name:'A1',age:50},
]
primaryKey 参数为 ['id','name'] 数据会经过整理,整理后变为
[
{id:'1',name:'A1',age:10},
{id:'1',name:'A1',age:50},
{id:'1',name:'A3',age:30},
{id:'2',name:'A2',age:20},
{id:'4',name:'A4',age:40},
]
mergeKey,可以设置数据对应的列,不填写则按照 primaryKey 的字段合并