vue element使用el-table时,切换tab,table表格列项发生错位问题

展示问题

问题描述:使用el-table的fixed="right"属性后,如果切换tab时,回出现最后一列错误的问题

官网提供解决方法:doLayout

  • 需要注意的事项:我这里是通过组件使用的table组件,涉及多层组件封装问题,所以找这个根组件ref找到doLayout方法的时候需要注意写法 (如果存在组件签套,记得多加几次$refs[refName]调用方法)
js 复制代码
<el-tabs v-model="searchParam.activeName" @tab-click="handleClick">
  <el-tab-pane label="统计" name="first">
    <leftTable
      ref="leftTableRef"
      :table-data-list="gateStatisticsListTable"
      :table-all="gateStatisticsListTableAll"
      :count="tableDataCount"
      :search-param="searchParam"
      @refresh="refresh"
      @export-all="exportAll"
      @change-page="changePage" />
  </el-tab-pane>
  <el-tab-pane label="明细" name="second">
    <rightTable
      ref="rightTableRef"
      :table-data-list="gateStatisticsListTable"
      :table-all="gateStatisticsListTableAll"
      :count="tableDataCount"
      :search-param="searchParam"
      @refresh="refresh"
      @export-all="exportAll"
      @change-page="changePage" />
  </el-tab-pane>
</el-tabs>
js 复制代码
 handleClick(tab, event) {
   this.$nextTick(() => {
    if (this.searchParam.activeName === 'first') {
      const that = this
      // 其中leftTableRef是el-table的ref
      that.$refs.leftTableRef.$refs.tableRef.doLayout()
      // 切换 tab请求接口
      this.queryData()
    }
    if (this.searchParam.activeName === 'second') {
      // 其中rightTableRef是el-table的ref
      const that = this
      that.$refs.rightTableRef.$refs.tableRef.doLayout()
      // 切换 tab请求接口
      this.queryData()
    }
  })
},

修改后的效果展示:

相关推荐
大胡子大叔几秒前
React组件化实现程序化视频生成
前端·react.js·音视频
wjcroom5 分钟前
融释涡旋理论-对狭义相对论和洛伦兹变换的兼容
开发语言·前端
2601_955354468 分钟前
SEO新手如何快速入门学习
前端·学习·搜索引擎
小和尚敲木头8 分钟前
router.push(‘/‘)跳转不触发重定向
开发语言·前端·javascript
misty youth9 分钟前
提示词合集【自用】
开发语言·前端·ai编程
zzginfo9 分钟前
ES6 中的 “?.” 可选链运算符用法
前端·ecmascript·es6
战族狼魂13 分钟前
Claude Code 源码泄露事件
前端·npm·node.js
We་ct15 分钟前
LeetCode 67. 二进制求和:详细题解+代码拆解
前端·数据结构·算法·leetcode·typescript
还是大剑师兰特15 分钟前
为什么要用 import.meta.glob 加载 SVG 图标库
开发语言·前端·javascript