Element-ui table splice 移除数组元素 页面只会删除最后一行 视图和数据不对等
搭建Vue后台,用了vue-element-admin开源项目,里面的Element-ui table表格删除元素视图更新有误
<el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%"> <el-table-column align="center" label="Actions" width="120"> <template slot-scope="scope"> <el-button-group> <el-button type="danger" size="small" icon="el-icon-delete" @click="deleteList(scope.row.id, scope.$index)" /> </el-button-group> </template> </el-table-column> </el-table> </el-table>
这里我要删除操作,移除一行数组,于是获得了id和数组index
deleteList(id, index) { console.log(index) this.list.splice(index, 1) }
操作完后,list数组是移除正确的,但是视图上把表格最后一行移除了,我很奇怪,难道element-ui的table遍历的数组对象不是我传递的list?不管我删除哪一个,视图上照样删除最后一行,甚至我重新调用接口赋值list也不行,视图和数据不对等
本作品采用《CC 协议》,转载必须注明作者和本文链接