You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
3.3 KiB
Vue

<template>
<div>
<el-alert
effect="dark"
:closable="false"
title="基于 Element 的 Table 组件进行二次封装,实现数据驱动,支持所有 Table 参数 -- 多级表头"
type="info"
style="margin-bottom: 20px;"
/>
<com-table
v-loading="loading"
:columns="columns"
:data="tableData"
>
<template #address="scope">
地址是: {{ scope.row.address }}
</template>
<template #action="scope">
<el-button type="text" size="small" @click="deleteRow(scope.$index)">移除</el-button>
</template>
</com-table>
</div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
const columns = [
{
key: 'date',
label: '',
fixed: true,
width: '150'
},
{
label: '',
children: [
{
key: 'name',
label: '',
width: '120'
},
{
label: '',
children: [
{
key: 'province',
label: '',
width: '120'
},
{
key: 'city',
label: '',
width: '120'
},
{
key: 'address',
label: '',
slots: {
default: 'address'
}
},
{
key: 'zip',
label: '',
width: '120'
}
]
}
]
},
{
key: 'action',
label: '',
width: '100',
slots: {
default: 'action'
}
}
]
export default defineComponent({
// name: 'MultiHeader',
setup() {
const tableData = ref<any[]>([
{
date: '2016-05-03',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-02',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-04',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-01',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-08',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-06',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}, {
date: '2016-05-07',
name: '王小虎',
province: '上海',
city: '普陀区',
address: '上海市普陀区金沙江路 1518 弄',
zip: 200333
}
])
const loading = ref<boolean>(true)
setTimeout(() => {
loading.value = false
}, 1000)
function deleteRow(index: number) {
tableData.value.splice(index, 1)
}
return {
columns,
tableData,
loading,
deleteRow
}
}
})
</script>
<style>
</style>