提交 ce21d137 编写于 作者: L lin-xin

修复表格顺序改变后误删其他数据

上级 8c33d1b5
{ {
"list": [{ "list": [{
"date": "1997-11-11", "id": 1,
"name": "林丽", "date": "2013-05-04",
"address": "吉林省 辽源市 龙山区" "name": "邱秀兰",
}, { "address": "浙江省 金华市 兰溪市"
"date": "1987-09-24", }, {
"name": "文敏", "id": 2,
"address": "江西省 萍乡市 芦溪县" "date": "1991-05-02",
}, { "name": "蒋军",
"date": "1996-08-08", "address": "广东省 东莞市 长安镇"
"name": "杨秀兰", }, {
"address": "黑龙江省 黑河市 五大连池市" "id": 3,
}, { "date": "2009-12-01",
"date": "1978-06-18", "name": "廖艳",
"name": "魏强", "address": "陕西省 渭南市 富平县"
"address": "广东省 韶关市 始兴县" }, {
}, { "id": 4,
"date": "1977-07-09", "date": "1999-07-15",
"name": "石秀兰", "name": "秦强",
"address": "江苏省 宿迁市 宿豫区" "address": "内蒙古自治区 巴彦淖尔市 磴口县"
}, { }, {
"date": "1994-09-20", "id": 5,
"name": "朱洋", "date": "1997-02-09",
"address": "海外 海外 -" "name": "唐洋",
}, { "address": "湖南省 长沙市 "
"date": "1980-01-22", }, {
"name": "傅敏", "id": 6,
"date": "2018-05-23",
"name": "易勇",
"address": "重庆 重庆市 双桥区"
}, {
"id": 7,
"date": "2014-04-09",
"name": "袁丽",
"address": "陕西省 铜川市 耀州区"
}, {
"id": 8,
"date": "2013-08-05",
"name": "常刚",
"address": "海外 海外 -" "address": "海外 海外 -"
}, { }, {
"date": "1985-10-10", "id": 9,
"name": "毛明", "date": "1995-12-13",
"address": "内蒙古自治区 包头市 九原区" "name": "龚勇",
"address": "黑龙江省 牡丹江市 西安区"
}, { }, {
"date": "1975-09-08", "id": 10,
"name": "何静", "date": "2017-06-06",
"address": "西藏自治区 阿里地区 普兰县" "name": "魏强",
}, { "address": "安徽省 六安市 裕安区"
"date": "1970-06-07",
"name": "郭秀英",
"address": "四川省 巴中市 恩阳区"
}] }]
} }
\ No newline at end of file
...@@ -87,7 +87,8 @@ ...@@ -87,7 +87,8 @@
date: '', date: '',
address: '' address: ''
}, },
idx: -1 idx: -1,
id: -1
} }
}, },
created() { created() {
...@@ -143,16 +144,18 @@ ...@@ -143,16 +144,18 @@
}, },
handleEdit(index, row) { handleEdit(index, row) {
this.idx = index; this.idx = index;
const item = this.tableData[index]; this.id = row.id;
this.form = { this.form = {
name: item.name, id: row.id,
date: item.date, name: row.name,
address: item.address date: row.date,
address: row.address
} }
this.editVisible = true; this.editVisible = true;
}, },
handleDelete(index, row) { handleDelete(index, row) {
this.idx = index; this.idx = index;
this.id = row.id;
this.delVisible = true; this.delVisible = true;
}, },
delAll() { delAll() {
...@@ -170,15 +173,33 @@ ...@@ -170,15 +173,33 @@
}, },
// 保存编辑 // 保存编辑
saveEdit() { saveEdit() {
this.$set(this.tableData, this.idx, this.form);
this.editVisible = false; this.editVisible = false;
this.$message.success(`修改第 ${this.idx+1} 行成功`); this.$message.success(`修改第 ${this.idx+1} 行成功`);
if(this.tableData[this.idx].id === this.id){
this.$set(this.tableData, this.idx, this.form);
}else{
for(let i = 0; i < this.tableData.length; i++){
if(this.tableData[i].id === this.id){
this.$set(this.tableData, i, this.form);
return ;
}
}
}
}, },
// 确定删除 // 确定删除
deleteRow(){ deleteRow(){
this.tableData.splice(this.idx, 1);
this.$message.success('删除成功'); this.$message.success('删除成功');
this.delVisible = false; this.delVisible = false;
if(this.tableData[this.idx].id === this.id){
this.tableData.splice(this.idx, 1);
}else{
for(let i = 0; i < this.tableData.length; i++){
if(this.tableData[i].id === this.id){
this.tableData.splice(i, 1);
return ;
}
}
}
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册