vue+elementui中的el-table中拼接接口返回的两个字段的数据并展示

时间:2024-03-17 08:02:46

最近刚学Vue,使用的elementui组件库,用到了table表格组件<el-table></el-table>标签

遇到个问题就是其中有个<el-table-column></el-table-column>要展示的数据来自接口返回的两个字段

原用法是:

<el-table :data="tableData(表格数据来源)" stripe style="width: 100%">

        <el-table-column prop="date(表格数据来源的某个字段)" label="日期(表格头部)" width="180">

</el-table-column>

原以为prop=" "中只能放一个字段的数据,想放两个字段数据的话,要把 <el-table-column></<el-table-column>标签再用

<template></template>标签包裹才行如下:

vue+elementui中的el-table中拼接接口返回的两个字段的数据并展示

<el-table :data="projNameOrCodeMenuList" class="parentNode"  @row-click="chooseParentNode">
  <el-table-column  class="parentNodeColumn" prop="projectName,projectCode" label="项目名称(代码)"  width="300">
    <template slot-scope="scope"> {{scope.row.projectName}}({{scope.row.projectCode}}) </template>
  </el-table-column>
</el-table>

记得原来<el-table-column></el-table-column>标签中的prop=" "中放两个字段名哈~还有

<template slot-scope="scope"></template>中的slot-scope="scope" 最后通过{{scope.row.字段名}}就行啦~:D