封装elementui的table组件

  |  

table.vue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<template>
<el-table
v-bind="$props"
border
:header-cell-style="{ 'text-align': 'center' }"
style="width: 100%"
>
<el-table-column
label="序号"
width="50"
align="center"
>
<template slot-scope="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
<template v-for="(col, key) in tableColumns">
<el-table-column
:key="key"
v-bind="col"
/>
</template>
</el-table>
</template>
<script lang="ts">
import { Vue, Component, Prop } from 'vue-property-decorator'
import { Table } from 'element-ui'
export type Column = {
label: string
prop?: string
width?: string
minWidth?: string
fixed?: string | boolean
align?: 'left' | 'center' | 'right'
formatter?: { (row: any, col: any, value: any): unknown }
// renderHeader的使用 https://www.cnblogs.com/yixiancheng/p/11525970.html
renderHeader?: { (h: any, { column, $index }: any): unknown }
}

@Component({
props: {
...(Table as any).props,
}
})
export default class extends Vue {
@Prop({ default: () => ([]) }) tableColumns!: Column
}
</script>