<el-table :data="tableData" style="width: 100%">
<el-table-column
prop="name"
label="固定字段名"
:formatter="formatter"
>
</el-table-column>
<el-table-column
v-for="(item, index) in wordsColumns"
:prop="item.name"
:label="item.label"
:key="index"
>
</el-table-column>
</el-table>
const tableData = ref(
[{
date: '2016-05-02',
id: '1',
name: '王小虎',
address: '上海市普陀区金沙江路 1518 弄'
}, {
date: '2016-05-04',
id: '2',
name:'章三',
address: '上海市普陀区金沙江路 1517 弄'
}, {
date: '2016-05-01',
id: '3',
name: '李四',
address: '上海市普陀区金沙江路 1519 弄'
}, {
date: '2016-05-03',
id: '4',
name: '王五',
address: '上海市普陀区金沙江路 1516 弄'
}]
);
const wordsColumns = [
{ name: "name", label: "姓名" },
{ name: "address", label: "地址" },
{ name: "date", label: "时间" },
];
const formatter = (row, column) => {
console.log(row, column)
switch (row.id) {
case '1':
return '用户1'
case '2':
return '用户2'
case '3':
return '用户3'
case '4':
return '用户4'
}
let newName = '用户' + row.name
return newName
};
页面展示: