刷新视图但不刷新选中状态/分页记住选中状态

是她丫

关注

阅读 32

2022-02-15

<!-- reserve-selection:仅对 type=selection 的列有效,类型为 Boolean,为 true 则会在数据更新之后保留之前选中的数据(需指定 row-key) -->
<table ref="tableRef" @selection-change="checkClick" :row-key="rowKey">
    <table-column type="selection" :reserve-selection="true"></table-column>
</table>
checkClick(selection) {
    this.selection = selection;
}

rowKey(row) {
    return row.cartId;
}

watch: {
    // val:表格数据源
    goodList(val) {
        val.forEach(item => {
            // 表中选中的数据列表
            vue.selection.forEach(self => {
                if(self.cartId === self.cartId) {
                    // 更新当前行的选中状态
                    vue.$refs.tableRef.toggleRowSelection(item, true);
                }
            })
        })
    }
}

精彩评论(0)

0 0 举报