1.分页时,之前选中操作还存在
代码中添加 row-key,:reserve-selection="true"属性
<el-table row-key="id" @selection-change="selectionChange">
<el-table-column
type="selection"
:reserve-selection="true"
width="50"
>
</el-table-column>
</el-table>
data:{
return(){
dataSelection:[],
b:[],//保存已经绑定数据元id
a:[],//保存已经绑定的的要取消的数据id
}
}
create(){
init(){
//初始化页面时,根据后端返回,添加对表的默认选中
//this.$refs.table.toggleRowSelection(v, true);
}
},
methods:{
selectionChange(val) {
this.dataSelection = val;
},
}
(默认有选中)分页时,之前选中操作还存在(即多页修改统一保存)
思路:
用一个数组a保存默认选中却删除的数据,
用一个数组b去保存当前页默认选中的数据
分页改变时,:
数组b和dataSelection 作比较,b中有的但dataSelection 中没有的,就把这种放在a中
当进入新的页面:if判断a的设成this.
r
e
f
s
.
t
a
b
l
e
.
t
o
g
g
l
e
R
o
w
S
e
l
e
c
t
i
o
n
(
v
,
f
a
l
s
e
)
;
e
l
s
e
判
断
默
认
选
中
的
t
h
i
s
.
refs.table.toggleRowSelection(v, false); else 判断默认选中的this.
refs.table.toggleRowSelection(v,false);else判断默认选中的this.refs.table.toggleRowSelection(v, true);
this.d.forEach(d=>{
let bool=false
this.dataSelection.forEach(item=>{
if(d.id==item.id){
bool=true
}
})
if(!bool){
this.a.push(d.id)
}
})