@Leopoldthecoder 这个真的好坑啊,如果这个Table是 在 mounted 之后动态渲染出来的呢?为什么不支持初始化选中呢?
多选的表格不能默认选中指定的行吗?急急急。。。
我用debugger以后发现,如果是在mounted才动态渲染表格,那么此时应该是无法默认选中的 。
因为此时的this.$refs.XXTable中,data的长度为0(相关数据已取得但未完成赋值,将在下一个周期完成赋值),而更新Selection方法中,恰恰是需要判断data的长度是否等于0,所以我估计是无法做到的。

除非可以在获取data数据并待完成表格数据赋值时才调用toggleSelection方法。
在mounted时无法调用toggleSelection方法,求解
watch table绑定的数据 就可以了
watch: {
docList(val, oldVal) {
if (val.length !== oldVal.length && oldVal.length === 0) {
setTimeout(() => {
this.$refs.multipleTable.toggleRowSelection(this.docList[0]);
}, 100);
}
}
},
this.$nextTick(function(){
this.$refs.multipleTable.toggleRowSelection(this.docList[0]);
})
经测试可用
if (res.status === 200) {
this.tableList = res.data.tableList
res.data.seletedIds.map(id => {
this.tableList.map((tableinfo, index) => {
if (tableinfo.id === id) {
this.$nextTick(function() {
this.$refs.sfTable.toggleRowSelection(this.tableList[index], true)
})
}
})
})
这个可用,具体啥原因,有人能解释吗?
如果不用nextTick,死活都不行。
Most helpful comment
this.$nextTick(function(){
this.$refs.multipleTable.toggleRowSelection(this.docList[0]);
})
经测试可用