项目场景:
使用<el-table>
显示列名含有.
的数据。
问题描述
如果使用<el-table>
的prop
属性那么含有.
的列将获取不到数据。
<el-table
:data="table.colValues"
style="width: 100%; margin-bottom: 20px"
row-key="key"
border
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column
v-for="(col, index) in Object.entries(table.colNames)"
:key="index"
:label="col[1]"
:prop="col[0]"
width="180"
/>
</el-table>
解决方案:
使用插槽进行显示:
<el-table
:data="table.colValues"
style="width: 100%; margin-bottom: 20px"
row-key="key"
border
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column
v-for="(col, index) in Object.entries(table.colNames)"
:key="index"
:label="col[1]"
:prop="col[0]"
width="180"
>
<template slot-scope="scope">
{{ scope.row[col[0]] }}
</template>
</el-table-column>
</el-table>