vue的table -Vue3中el-table-column v-show无效问题 - hidden-column'
在 Vue3 + Element Plus 的 el-table-column 中使用 v-show="false" 不起作用的原因及解决方案:
问题原因
el-table-column 不是常规的 DOM 元素,它是一个组件,v-show 对其渲染逻辑影响有限
Element Plus 表格列有自己的渲染机制,主要通过其他方式控制列的显示隐藏
解决方案
方案1:使用 v-if(推荐)
vue 拼多多帮助力入口
v-if="showColumn"
prop="lqPerson"
label="领取人"
width="100"
header-align="center"
sortable
show-overflow-tooltip
>
方案2:动态设置 width 为 0
vue
:width="columnVisible ? 100 : 0"
prop="lqPerson"
label="领取人"
header-align="center"
sortable
show-overflow-tooltip
>
方案3:使用 CSS 类控制
vue
:class="{ 'hidden-column': !columnVisible }"
prop="lqPerson"
label="领取人"
width="100"
header-align="center"
sortable
show-overflow-tooltip
>
方案4:动态列配置(适用于复杂场景)
vue
推荐做法
使用 v-if 是最直接有效的方式:
完全从 DOM 中移除列
性能较好
代码简洁明了
vue
v-if="isLqPersonVisible"
prop="lqPerson"
label="领取人"
width="100"
header-align="center"
sortable
show-overflow-tooltip
>
这样就能完美解决 v-show 在 el-table-column 上不起作用的问题了。,vue的table