要使用nextTick()方法+element表格中的toggleRowSelection()方法
记得在table标签中添加ref
<el-table :data="list" ref="multipleTableRef"> <el-table-column type="selection" width="55"> </el-table-column> <el-table-column prop="name" label="名称"></el-table-column> </el-table>
vue代码:
queryBadgeToSet(query) { var self = this; this.$http.post(API_ROOT.tjk + '/query', this.searchData).then(response => { var result = response.data; if(result.success) { self.dialogBadgeSet.badgeList = result.data;//拿到数据,准备开始渲染 // 等待tableData.value被赋值,DOM更新后再设置默认勾选 self.toggleSelection(self.dialogBadgeSet.badgeList); }else { this.$alert(result.msg) } }, response => { this.$alert('网络繁忙,请稍后重试!') }) }, toggleSelection(rows){ var self = this; self.$nextTick(() => { rows.forEach((k,i)=>{ var checkedOrNot = k.tjkBadgeId != null; self.$refs.multipleTableRef.toggleRowSelection(k, checkedOrNot); //true 说明显示被勾选 }) }); },
标签:el,回显,self,勾选,result,var,table,response From: https://www.cnblogs.com/xiaoliu66007/p/18493204