在项目中,遇到了不固定表头,记录一下。
<el-table border stripe :data="listData">
<el-table-column v-for="item,index in tableList" :key="index" :label="item.label" :prop="item.prop">
<template slot-scope="scope">
<div>{{scope.row[scope.column['property']]}}</div>
</template>
</el-table-column>
</el-table>
<script>
export default {
data(){
return {
// 动态表头信息 后端返回
tableList:[{
label:'表头1',
prop:'ch'
}],
listData:[
{
"ch":123
}
]
}
}
}
</script>