问题:vue2+elementui,tabs切换显示表格并设置表格选中行高亮失败

错误示范:

1.直接setCurrentRow失败(this.currentRow是之前保存的表格当前选中行的数据)

javascript 复制代码
this.$refs.table.setCurrentRow(this.currentRow);

2.以为是表格没生成就执行了setCurrentRow导致设置不成功,所以使用了this.$nextTick,依旧失败

javascript 复制代码
this.$nextTick(() => {
	this.$refs.table.setCurrentRow(this.currentRow);
});

最后解决:

好吧,最后发现问题出在setCurrentRow的参数上,不管你有没有改动表格数据,用你需要选中的行id,去遍历表格数据,遍历到item.id===id,则row =item,最后用this.$refs.table.setCurrentRow(row)可以解决。

完整代码如下:

javascript 复制代码
this.$nextTick(() => {
	let currentRow = this.tableData.filter(item => {
		return item.id === this.currentRowId;
	});
	console.log("有选中行", currentRow[0]);
	this.$refs.table.setCurrentRow(currentRow[0]);
});

这个nextTick因为写了就没去掉,不包可能也行吧。

这是之前参数的由来:

参考:

相关推荐
发现一只大呆瓜3 分钟前
Vite凭什么这么快?3分钟带你彻底搞懂 Vite 热更新的幕后黑手
前端·面试·vite
Maimai1080814 分钟前
React如何用 @microsoft/fetch-event-source 落地 SSE:比原生 EventSource 更灵活的实时推送方案
前端·javascript·react.js·microsoft·前端框架·reactjs·webassembly
candyTong17 分钟前
Claude Code 的 Edit 工具是怎么工作的
javascript·后端·架构
kyriewen2 小时前
产品经理把PRD写成“天书”,我用AI半小时重写了一遍,他当场愣住
前端·ai编程·cursor
humcomm2 小时前
元框架的工作原理详解
前端·前端框架
canonical_entropy3 小时前
Attractor Before Harness: AI 大规模开发的方法论
前端·aigc·ai编程
zhangxingchao3 小时前
多 Agent 架构到底怎么选?从 Claude Agent Teams、Cognition/Devin 到工程落地原则
前端·人工智能·后端
IT_陈寒3 小时前
SpringBoot那个自动配置的坑,害我排查到凌晨三点
前端·人工智能·后端
Honor丶Onlyou3 小时前
VS Code 右键菜单修复记录
前端
卡卡军3 小时前
agmd 1.0 重磅升级——Rust 重写,性能起飞
javascript·rust