当前位置:网站首页>el-table实现可编辑表格
el-table实现可编辑表格
2022-07-26 10:35:00 【Suzerk】
实现el-table的可编辑表格如图所示:

以下展示部分代码:
<el-table-column label="价格" min-width="20" align="center">
<template slot-scope="scope">
<el-input
v-if="scope.row.edit"
v-model="scope.row.price"
placeholder="价格"
></el-input>
<span v-else>{
{
scope.row.price }}</span>
</template>
</el-table-column>
<el-table-column label="库存" min-width="20" align="center">
<template slot-scope="scope">
<el-input
v-if="scope.row.edit"
v-model="scope.row.store"
placeholder="库存"
></el-input>
<span v-else>{
{
scope.row.store }}</span>
</template>
</el-table-column>
<el-table-column
label="操作"
align="center"
width="230"
class-name="small-padding fixed-width"
>
<template slot-scope="scope">
<el-button
@click="confirmData(scope.row)"
v-if="scope.row.edit"
type="success"
size="medium"
>
<i class="el-icon-check" aria-hidden="true"></i>
</el-button>
<div v-else>
<el-button
type="primary"
size="medium"
@click="editData(scope.row)"
>
<i class="el-icon-edit" aria-hidden="true"></i>
</el-button>
<el-button
type="danger"
size="medium"
@click="handleDelete(scope)"
>
<i class="el-icon-delete" aria-hidden="true"></i>
</el-button>
</div>
</template>
</el-table-column>
methods:
editData(row) {
row.edit = true;
// console.log(row.edit);
// console.log(row.price);
},
confirmData(row) {
row.edit = false;
// console.log(row.edit);
// console.log(row.price);
this.$notify({
title: "Success",
message: "编辑成功",
type: "success",
duration: 2000,
});
handleDelete(row, index) {
this.$notify({
title: "Success",
message: "Delete Successfully",
type: "success",
duration: 2000,
});
this.list.splice(index, 1);
},
注意:这样写了以后发现点击按钮改变edit值时,不能立刻反应在view中,而且每行会影响,于是动态给所有数组记录 添加edit属性。
在getList方法中实现给数组加edit属性。
let data = JSON.parse(JSON.stringify(this.list ? this.list : []));
data.forEach((element) => {
element["edit"] = false;
});
this.list = data;
边栏推荐
- 卸载魅族应用商店
- .net operation redis string string
- js 获得当前时间,时间与时间戳的转换
- SuperMap IClient for Leaflet 加载高斯克吕格投影三度分带CGCS2000大地坐标系WMTS服务
- Tradingview 使用教程
- The difference between equals and = =
- Interview questions and answers of the first company (I)
- 404页面和路由钩子
- .net operation redis list list
- C language calculation date interval days
猜你喜欢

Agenda express | list of sub forum agenda on July 27

404页面和路由钩子
![[Halcon vision] morphological expansion](/img/ce/abaca036fce5b67dfe6ac361aecfea.png)
[Halcon vision] morphological expansion

第5期:大学生入职必备技能之二
![[Halcon vision] image filtering](/img/7a/b95f8977f02fab644ef9fb205424e7.png)
[Halcon vision] image filtering

Oracle cannot start tnslistener service cannot start

Mlx90640 infrared thermal imager temperature sensor module development notes (VI) pseudo color coding of infrared images

【机器学习小记】【风格迁移】deeplearning.ai course4 4th week programming(tensorflow2)

.NET 开源框架在工业生产中的应用
![[Halcon vision] array](/img/29/905d93795a24538fded18d2d377e52.png)
[Halcon vision] array
随机推荐
议程速递 | 7月27日分论坛议程一览
Okaleido生态核心权益OKA,尽在聚变Mining模式
404页面和路由钩子
Navicat15 MySQL (centos7) connected to local virtual machine
String null to empty string (what does empty string mean)
STM32 Alibaba cloud mqtt esp8266 at command
将json文件中数组转换为struct
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
.net operation redis sorted set ordered set
移动端H5开发常用技巧总结
Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
[leetcode每日一题2021/2/14]765. 情侣牵手
Redis special data type usage scenarios
Write to esp8266 burning brush firmware
Controller返回JSON数据
第8期:云原生—— 大学生职场小白该如何学
.NET5WTM(ASP.NET Core) PGSql开箱操作
[leetcode每日一题2021/8/30]528. 按权重随机选择【中等】
多目标优化系列1---NSGA2的非支配排序函数的讲解
[Halcon vision] Fourier transform of image