通过按钮实现表格行内编辑和删除操作

需求概述

表头和表格数据都来自于后台,在表格的最后一列加上操作列,操作列中存放编辑和删除按钮,当表格行处于编辑状态时,按钮变为保存和修改按钮。
关于编辑状态的切换参考自: 链接.

完整代码

<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>

            <!-- 在末尾再加上一列
  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值