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也不行,视图和数据不对等
阅读 4k
1 个回答

没毛病

<el-table v-loading="listLoading" :data="arr" border fit highlight-current-row style="width: 100%">
            <el-table-column align="center" label="Actions" width="120" prop="name">
            </el-table-column>
            <el-table-column align="center" label="Actions" width="120" prop="name">
                <template slot-scope="scope">
                <el-button-group>
                    <el-button type="danger" size="small" icon="el-icon-delete" @click="deleteList(scope.row, scope.$index)" />
                </el-button-group>
                </template>
            </el-table-column>
        </el-table>
<script>
export default {
    data(){
        return{
            arr:[
                {
                    name:'fgf'
                },
                {
                    name:'fgfd'
                },
                {
                    name:'fgft'
                },
                {
                    name:'fgfb'
                },
                {
                    name:'fgfw'
                },
                {
                    name:'fgfy'
                }
            ]
        }
    },
    mounted(){

    },
    methods:{
        deleteList(item,i){
            this.arr.splice(i,1)
        }
    }
}
</script>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题