vue 两个表格相同时,选择项数据保持同步

当一个vue页面同时出现两个相同的表格(el-table),在切换el-tabs标签时,要让他们的选择项保持一致。
1.一种思路直接用toggleRowSelection改变选择,对应的另一个表格也选择上,但是selection-change方法获取的数据不对,而且只能一个一个的遍历每一行。
2.第二种思路直接改变表格对象的属性。打印表格对象发现 this.$refs.realDataTabel中有一个selection属性,直接把要选中的选项数据放进去就可以了

//提前把选中的选项放到this.selectedRows中。
//1.第一个表格切换到同步到第二个表格时
let _this=this
_this.$refs.realDataTabel.selection.length = 0
this.selectedRows.forEach(function (item,index) {
    
    
    _this.$refs.realDataTabel.selection.push(item);
})
//2.第二个表格切换到同步到第一个表格时
_this.$refs.realHistoryDataTabel.selection.length = 0
this.selectedRows.forEach(function (item,index) {
    
    
	_this.$refs.realHistoryDataTabel.selection.push(item);
})

注意_this.$refs.realDataTabel.selection不能直接赋值为[],会报错

猜你喜欢

转载自blog.csdn.net/baby_dewo/article/details/113172748
今日推荐