需求概述
表头和表格数据都来自于后台,在表格的最后一列加上操作列,操作列中存放编辑和删除按钮,当表格行处于编辑状态时,按钮变为保存和修改按钮。
关于编辑状态的切换参考自: 链接.
完整代码
<template>
<el-container class="fillcontain">
<el-main>
<el-row>
<el-col :span="24" ref="right">
<el-table
:data="tableData"
style="margin-top: 5px; width: 100%"
border
>
<!-- 循环表头数据,加载出所有的列 -->
<template v-for="(child, index) in tableHead">
<el-table-column
:key="index"
:label="child.name"
:prop="child.prop"
:min-width="child.width"
:align="child.align"
show-overflow-tooltip
resizable
>
<!-- 利用show属性来控制el-input与span之间的切换显隐 -->
<template slot-scope="scope">
<el-input
v-show="scope.row.show"
v-model="scope.row[child.prop]"
></el-input>
<span v-show="!scope.row.show">{
{
scope.row[child.prop]
}}</span>
</template>
</el-table-column>
</template>
<!-- 在末尾再加上一列操作列&#