vue动态控制el-table表格每一列的显示

在实际需求中我们常遇见这样的需求:

我们需要像如下方式一样动态控制表列的显示;

实现方法:

html:

        <el-popover placement="bottom-end" width="370" trigger="hover">
            <el-button
              slot="reference"
              class="cu-ordinaryBtn"
              icon="icon iconfont icon-shezhi-xianxing"
              style="margin-right: 10px"
              >设置</el-button
            >
            <template slot>
                <div>
                  <el-checkbox-group
                    v-model="checkedTableLines"
                    style="padding: 10px; padding-top: 0px"
                  >
                    <el-checkbox
                      style="margin-top: 15px"
                      v-for="item in tableLines"
                      :label="item"
                      :key="item"
                    >
                      {{ item }}
                    </el-checkbox>
                  </el-checkbox-group>
              </div>
            </template>
          </el-popover>

script:

<script>
	const tabLineOptions = [
		"房屋编码",
		"建筑面积",
		"使用面积",
		"朝向",
		"房屋性质",
		"房屋用途",
		"装修性质",
		"备注",
		"添加时间",
		"创建账号",
	];
	export default {
       data() {
		 return {
            	checkedTableLines: [
					"建筑面积",
					"使用面积",
					"朝向",
					"房屋性质",
					"房屋用途",
					"装修性质",
				],
				cities: tabLineOptions,
         }
       }
    }

最后在el-table列表项中添加:

v-if="checkedCities.indexOf('列表项名称') != -1"就可以实现动态控制table列表项了。如:

<el-table-column align="left" sortable="custom" prop="buildingUseType" label="房屋用途"
   v-if="checkedCities.indexOf('房屋用途') != -1">
</el-table-column>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阁下何不同风起?

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值