当前位置:网站首页>el-table实现增加/删除行,某参数跟着变
el-table实现增加/删除行,某参数跟着变
2022-07-26 09:21:00 【周小盗】
效果展示:


当在中间删除或添加行时,最左侧步骤的内容也会跟着变。
代码展示:
首先,html中的el-table代码:
<el-table-self :data="setList" style="width: 100%" max-height="250">
<el-table-column align="center" prop="orderNum" label="步骤" width="80">
<template slot-scope="scope">
<span>第{
{
scope.row.orderNum}}步</span>
</template>
</el-table-column>
<el-table-column align="center" prop="type" label="类型">
<template slot-scope="scope">
<el-select
size="small"
v-model="scope.row.type" placeholder="请选择">
<el-option
v-for="item in typeOptions"
:key="item.value"
:label="item.label"
:value="item.value">
</el-option>
</el-select>
</template>
</el-table-column>
<el-table-column align="center" prop="realname" label="审批用户">
<template slot-scope="scope">
<el-select
size="small"
:disabled="scope.row.type!=='1'"
v-model="scope.row.userId"
placeholder="请选择">
<el-option
v-for="item in userList"
:key="item.id"
:label="item.realname"
:value="item.id">
</el-option>
</el-select>
</template>
</el-table-column>
<el-table-column align="center" prop="roleName" label="审批角色">
<template slot-scope="scope">
<el-select
size="small"
:disabled="scope.row.type!=='2'"
v-model="scope.row.roleId"
placeholder="请选择">
<el-option
v-for="item in roleList"
:key="item.id"
:label="item.roleName"
:value="item.id">
</el-option>
</el-select>
</template>
</el-table-column>
<el-table-column prop="flowCode" label="流程编码" ></el-table-column>
<el-table-column fixed="right" align="center" label="操作" width="180">
<template slot-scope="scope">
<el-button size="mini" type="primary" icon="el-icon-plus"
@click.native.prevent="addRow(scope.$index, setList)"></el-button>
<el-button size="mini" type="primary" icon="el-icon-minus"
@click.native.prevent="deleteRow(scope.$index, setList)"></el-button>
</template>
</el-table-column>
</el-table-self>
然后,methods中需要有三个方法:(如下)
//第一:获取el-table中的数据 setList
getcheckedId() {
this.$axios({
//url和各个参数
}).then((res) => {
//将获取到的返回值赋值给setList
this.setList=res.data
//如果setList中没有数据,则手动push一条数据,可以展示 + ,— 号
if(this.setList.length<1){
this.setList.push({
flowCode:'',
orderNum: res.data.length+1,
realname: '',
userId: '',
remark: "",
roleId: "",
roleName: "",
scope: 0,
updateTime: null,
})
}
}).catch(() => {
// return
})
},
//第二:点击 + 号执行添加一行数据的方法
addRow(index, rows) {
//用数组的splice方法从index+1位置删除0个元素,并插入一条空数据
rows.splice(index+1,0,{
flowCode:'',
orderNum: index+2,
realname: '',
userId: '',
remark: "",
roleId: "",
roleName: "",
scope: 0,
updateTime: null,
});
},
//第三:点击 — 号执行删除一行的方法
deleteRow(index, rows) {
//利用数组的splice方法,将该index数据删除
rows.splice(index, 1);
},
最终要的一点,对orderNum(步骤编号)的处理——对setList的数据进行监听
setList:{
handler: function (newVal,oldVal) {
// console.log("监听setList长度",newVal.length,oldVal.length)
if(newVal.length){
for(let i in newVal){
//实时获取orderNum的值
newVal[i].orderNum=Number(i)+1
}
}
//这里用来判断,如果是用户审批,就把角色制空;如果是角色审批,就把用户制空
for(let i in newVal){
if(newVal[i].type==='1'){
newVal[i].roleId=''
newVal[i].roleName=''
}else if(newVal[i].type==='2'){
newVal[i].userId=''
newVal[i].realname=''
}
}
},
deep: true //深度监听
}
结束语:
以上,就可以实现我们想要的结果了!(ps:写博客是为了记笔记!)
边栏推荐
- Innovus卡住,提示X Error:
- Original root and NTT 5000 word explanation
- 839. Simulation reactor
- Simple message mechanism of unity
- Error: Cannot find module ‘umi‘ 问题处理
- 838. Heap sorting
- ONTAP 9文件系统的限制
- Announcement | FISCO bcos v3.0-rc4 is released, and the new Max version can support massive transactions on the chain
- 756. Serpentine matrix
- 会议OA项目(三)---我的会议(会议排座、送审)
猜你喜欢

Cat installation and use

Advanced mathematics | Takeshi's "classic series" daily question train of thought and summary of error prone points

redis原理和使用-基本特性

围棋智能机器人阿法狗,阿尔法狗机器人围棋

Innovus is stuck, prompting x error:

The Child and Binary Tree-多项式开根求逆

Use of off heap memory

Qtcreator reports an error: you need to set an executable in the custom run configuration

redis原理和使用-安装和分布式配置

Elastic APM installation and use
随机推荐
Li Mu D2L (IV) -- softmax regression
Sending and receiving of C serialport
CF1481C Fence Painting
The essence of attack and defense strategy behind the noun of network security
Cat installation and use
Object type collections are de duplicated according to the value of an attribute
What is asynchronous operation
Force button list question
CF1481C Fence Painting
volatile 靠的是MESI协议解决可见性问题?(下)
csdn空格用什么表示
【Flutter -- 布局】Align、Center、Padding 使用详解
JS output diamond on the console
【线上问题】Timeout waiting for connection from pool 问题排查
Redis principle and use - Basic Features
redis原理和使用-基本特性
“could not build the server_names_hash, you should increase server_names_hash_bucket_size: 32” 问题处理
The problem of the sum of leetcode three numbers
Error: Cannot find module ‘umi‘ 问题处理
[MySQL] how to execute an SQL statement (2)