Vue ant design组件库 table表格删除一整行 为什么splice不行
<a-table
:columns="columns"
:rowKey="record => record.id"
:dataSource="data"
:pagination="pagination"
:loading="loading"
@change="handleTableChange"
bordered
>
<template
slot="name" slot-scope="text, record">
<span>{{reportName}}
<a-button type="primary"
@click="onDelete(record.key)">删除</a-button>
</span>
</template>
const dataSource = [...this.dataSource];
this.dataSource = dataSource.filter(item => item.key !== key);
实际是删除了数据源对应得哪一行数据就可以
ant-design就是不支持splice删除数据的方式
可以用filter删除
deleteRecord = (id) => {
let newData = this.state.dataSources.filter(function (item) {
return item.id !== id//返回你选中删除之外的所有数据
})
this.setState({
dataSources: newData
})
}