子组件myTable
<template>
<el-table
:data="tableData"
size="small"
border
:cell-style="cellStyle"
:header-cell-style="headerStyle"
class="table"
:max-height="tableHeight"
@selection-change="handleSelection"
>
<el-table-column v-if="showSelection" type="selection" />
<el-table-column v-for="item in columnList" :key="item.prop" :label="item.label" :prop="item.prop" :width="item.width?item.width:null"
:formatter="item.formatter?item.formatter: null" />
<!--表格操作列插槽-->
<slot name="tableControl" v-if="showTableControl" />
</el-table>
</template>
<script>
import constants from '~/plugins/constants'
export default {
name: 'MyTable',
props: {
// 表格数据
tableData: {
type: Array,
default: () => []
},
// 是否显示多选列表
showSelection: {
type: Boolean,
default: false
},
// 列的数据 lable prop等
columnList: {
type: Array,
default: () => []
},
// 是否显示表格操作列
showTableControl: {
type: Boolean,
default: false
}
},
data () {
return {
tableHeight: 0
}
},
mounted () {
this.$nextTick(() => {
this.tableHeight = this.setTableHeight()
})
},
methods: {
// 设置表格最大高度
setTableHeight () {
const table = document.querySelector('.table')
const top = table.offsetTop
return window.innerHeight - top - 70
// return result
},
cellStyle () {
return {
textAlign: 'center'
}
},
headerStyle () {
return {
textAlign: 'center',
backGroundColor: 'red'
}
},
handleSelection (val) {
this.$emit('handleSelection', val)
}
}
}
</script>
<style scoped>
</style>