ZBLOG

根据你的代码片段,你希望在 activeKey'3' 时不展示操作列。以下是解决方案:

方法1:动态控制 columns 数组

  1. const columns = [
  2. // 其他列...
  3. ...(!['3'].includes(activeKey) ? [{
  4. title: '操作',
  5. key: 'operation',
  6. fixed: 'right',
  7. width: 240
  8. }] : [])
  9. ]

方法2:使用 v-if 控制整个列(推荐)

修改你的模板部分:

  1. <template v-if="!['3'].includes(activeKey)">
  2. <column
  3. title="操作"
  4. key="operation"
  5. fixed="right"
  6. width="240">
  7. <!-- 你的操作按钮代码 -->
  8. </column>
  9. </template>

Vue3 + Ant Design Vue 完整示例:

  1. <a-table :columns="filteredColumns" :data-source="data">
  2. <script setup>
  3. import { computed } from 'vue';
  4. const props = defineProps({
  5. activeKey: String
  6. });
  7. const baseColumns = [
  8. { title: 'ID', dataIndex: 'id' },
  9. // 其他固定列...
  10. ];
  11. const operationColumn = {
  12. title: '操作',
  13. key: 'operation',
  14. fixed: 'right',
  15. width: 240,
  16. };
  17. const filteredColumns = computed(() => {
  18. return props.activeKey !== '3'
  19. ? [...baseColumns, operationColumn]
  20. : baseColumns;
  21. });
  22. </script>

这样当 activeKey'3' 时,操作列将不会渲染到表格中。

注意:如果你使用的是 JSX/TSX,逻辑类似,只需要调整语法即可。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=23116

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?