File tree Expand file tree Collapse file tree 2 files changed +74
-43
lines changed Expand file tree Collapse file tree 2 files changed +74
-43
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"list" : [{
3
- "date" : " 1997-11-11" ,
4
- "name" : " 林丽" ,
5
- "address" : " 吉林省 辽源市 龙山区"
6
- }, {
7
- "date" : " 1987-09-24" ,
8
- "name" : " 文敏" ,
9
- "address" : " 江西省 萍乡市 芦溪县"
10
- }, {
11
- "date" : " 1996-08-08" ,
12
- "name" : " 杨秀兰" ,
13
- "address" : " 黑龙江省 黑河市 五大连池市"
14
- }, {
15
- "date" : " 1978-06-18" ,
16
- "name" : " 魏强" ,
17
- "address" : " 广东省 韶关市 始兴县"
18
- }, {
19
- "date" : " 1977-07-09" ,
20
- "name" : " 石秀兰" ,
21
- "address" : " 江苏省 宿迁市 宿豫区"
22
- }, {
23
- "date" : " 1994-09-20" ,
24
- "name" : " 朱洋" ,
25
- "address" : " 海外 海外 -"
26
- }, {
27
- "date" : " 1980-01-22" ,
28
- "name" : " 傅敏" ,
3
+ "id" : 1 ,
4
+ "date" : " 2013-05-04" ,
5
+ "name" : " 邱秀兰" ,
6
+ "address" : " 浙江省 金华市 兰溪市"
7
+ }, {
8
+ "id" : 2 ,
9
+ "date" : " 1991-05-02" ,
10
+ "name" : " 蒋军" ,
11
+ "address" : " 广东省 东莞市 长安镇"
12
+ }, {
13
+ "id" : 3 ,
14
+ "date" : " 2009-12-01" ,
15
+ "name" : " 廖艳" ,
16
+ "address" : " 陕西省 渭南市 富平县"
17
+ }, {
18
+ "id" : 4 ,
19
+ "date" : " 1999-07-15" ,
20
+ "name" : " 秦强" ,
21
+ "address" : " 内蒙古自治区 巴彦淖尔市 磴口县"
22
+ }, {
23
+ "id" : 5 ,
24
+ "date" : " 1997-02-09" ,
25
+ "name" : " 唐洋" ,
26
+ "address" : " 湖南省 长沙市 "
27
+ }, {
28
+ "id" : 6 ,
29
+ "date" : " 2018-05-23" ,
30
+ "name" : " 易勇" ,
31
+ "address" : " 重庆 重庆市 双桥区"
32
+ }, {
33
+ "id" : 7 ,
34
+ "date" : " 2014-04-09" ,
35
+ "name" : " 袁丽" ,
36
+ "address" : " 陕西省 铜川市 耀州区"
37
+ }, {
38
+ "id" : 8 ,
39
+ "date" : " 2013-08-05" ,
40
+ "name" : " 常刚" ,
29
41
"address" : " 海外 海外 -"
30
42
}, {
31
- "date" : " 1985-10-10" ,
32
- "name" : " 毛明" ,
33
- "address" : " 内蒙古自治区 包头市 九原区"
43
+ "id" : 9 ,
44
+ "date" : " 1995-12-13" ,
45
+ "name" : " 龚勇" ,
46
+ "address" : " 黑龙江省 牡丹江市 西安区"
34
47
}, {
35
- "date" : " 1975-09-08" ,
36
- "name" : " 何静" ,
37
- "address" : " 西藏自治区 阿里地区 普兰县"
38
- }, {
39
- "date" : " 1970-06-07" ,
40
- "name" : " 郭秀英" ,
41
- "address" : " 四川省 巴中市 恩阳区"
48
+ "id" : 10 ,
49
+ "date" : " 2017-06-06" ,
50
+ "name" : " 魏强" ,
51
+ "address" : " 安徽省 六安市 裕安区"
42
52
}]
43
53
}
Original file line number Diff line number Diff line change 87
87
date: ' ' ,
88
88
address: ' '
89
89
},
90
- idx: - 1
90
+ idx: - 1 ,
91
+ id: - 1
91
92
}
92
93
},
93
94
created () {
143
144
},
144
145
handleEdit (index , row ) {
145
146
this .idx = index;
146
- const item = this . tableData [index] ;
147
+ this . id = row . id ;
147
148
this .form = {
148
- name: item .name ,
149
- date: item .date ,
150
- address: item .address
149
+ id: row .id ,
150
+ name: row .name ,
151
+ date: row .date ,
152
+ address: row .address
151
153
}
152
154
this .editVisible = true ;
153
155
},
154
156
handleDelete (index , row ) {
155
157
this .idx = index;
158
+ this .id = row .id ;
156
159
this .delVisible = true ;
157
160
},
158
161
delAll () {
170
173
},
171
174
// 保存编辑
172
175
saveEdit () {
173
- this .$set (this .tableData , this .idx , this .form );
174
176
this .editVisible = false ;
175
177
this .$message .success (` 修改第 ${ this .idx + 1 } 行成功` );
178
+ if (this .tableData [this .idx ].id === this .id ){
179
+ this .$set (this .tableData , this .idx , this .form );
180
+ }else {
181
+ for (let i = 0 ; i < this .tableData .length ; i++ ){
182
+ if (this .tableData [i].id === this .id ){
183
+ this .$set (this .tableData , i, this .form );
184
+ return ;
185
+ }
186
+ }
187
+ }
176
188
},
177
189
// 确定删除
178
190
deleteRow (){
179
- this .tableData .splice (this .idx , 1 );
180
191
this .$message .success (' 删除成功' );
181
192
this .delVisible = false ;
193
+ if (this .tableData [this .idx ].id === this .id ){
194
+ this .tableData .splice (this .idx , 1 );
195
+ }else {
196
+ for (let i = 0 ; i < this .tableData .length ; i++ ){
197
+ if (this .tableData [i].id === this .id ){
198
+ this .tableData .splice (i, 1 );
199
+ return ;
200
+ }
201
+ }
202
+ }
182
203
}
183
204
}
184
205
}
You can’t perform that action at this time.
0 commit comments