element table编辑当前行,使用自定义input操作

先看效果图

 

 点击编辑

 

 上源码!

<el-table-column label="父级工资项字段" prop="salholdPer" width="120" align="center">
                                <template slot-scope="scope">
                                    <el-input
                                        v-if="updateSwitch&&scope.$index===updateIndex"
                                        v-model="updateForm.salholdPer"
                                        :placeholder="scope.row.salholdPer!==null?scope.row.salholdPer:'请输入'"
                                    ></el-input>
                                    <span v-else>{{scope.row.salholdPer}}</span>
                                </template>
                            </el-table-column>
                            <el-table-column label="是否底级工资项" prop="salholdIsLeaf" width="120" align="center">
                                <template slot-scope="scope">
                                    <el-select
                                        v-if="updateSwitch&&scope.$index===updateIndex"
                                        v-model="updateForm.salholdIsLeaf"
                                        :placeholder="scope.row.salholdIsLeaf!==null?scope.row.salholdIsLeaf:'请选择'"
                                    >
                                        <el-option label="是" value="1"></el-option>
                                        <el-option label="否" value="0"></el-option>
                                    </el-select>
                                    <span v-else>{{scope.row.salholdIsLeaf==="1"?"是":"否"}}</span>
                                </template>
                            </el-table-column>

按钮部分

<template slot-scope="scope">
                                    <el-button
                                        type="text"
                                        icon="el-icon-lx-edit"
                                        @click="rowUpdate(scope.$index, scope.row)"
                                        v-show="!updateSwitch"
                                    >编辑</el-button>
                                    <el-button
                                        type="text"
                                        icon="el-icon-lx-edit"
                                        @click="submitRowUpdate()"
                                        v-show="updateSwitch&&scope.$index===updateIndex"
                                    >确定</el-button>
                                    <el-button
                                        type="text"
                                        icon="el-icon-lx-edit"
                                        @click="stopRowUpdate()"
                                        v-show="updateSwitch&&scope.$index===updateIndex"
                                    >取消</el-button>
                                    <el-button
                                        v-if="scope.row.isDeleted==='0'"
                                        size="small"
                                        type="text"
                                        icon="el-icon-close"
                                        @click="rowDisable(scope.$index, scope.row)"
                                        style="color:#909090"
                                    >停用</el-button>
                                    <el-button v-else size="small" type="text" icon="el-icon-check" @click="rowDisable(scope.$index, scope.row)">启用</el-button>
                                </template>

点击按钮穿参就不用多说了吧。

需要对当前操作行index进行判断(不然你知道修改的是哪行数据嘛),并且添加一个是否正在编辑的控制字段updateSwitch。

点击编辑按钮会获取编辑行index,改变控制字段的状态。更改完确认提交,完事!

菜鸡学习笔记,有不足或者表述不清楚的地方,欢迎大佬指点评论。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值