首先,我的需求是在el表格加载数据的时候在一定情况下默认选中某些行
参考官方:
首先在table里加了ref
<el-table ref=“reftable” v-loading=“loading2” :data=“goodsList” @selection-change=“handleSelectionChange2”>
然后:js文件
getGoodsList() {
this.loading2 = true;
this.theckedArrData = [];
listGoods(this.queryParams3).then(response => {
this.goodsList = response.rows;
this.goodsList.filter((good)=>{
if(good.id == 2){
this.theckedArrData.push(good);
}
})
this.total2 = response.total;
this.loading2 = false;
}).then(res=>{
this.cheched();
});
},
cheched(){
console.log(this.theckedArrData)
this.theckedArrData.filter((good)=>{
this.$refs.reftable.toggleRowSelection(good,true)
})
},
太牛了!!!!!!!!!!