vue+element UI实现table增加隐藏列操作

mounted() {

    // 发请求得到showColumnInitData的列的名字

    if(localStorage.getItem("columnSet")){

      this.showColumn = JSON.parse(localStorage.getItem("columnSet"))

    }else{

      this.showColumn = {

        name: true,

        age: true,

        city: true,

      };

    }

  },
    isEatCom: false,
      visible: false,
      // 列的配置化对象,存储配置信息
      showColumn: {
        name: true,
        age: true,
        city: true,
      },

 这里是在表格中增加了一个操作入口,以弹窗的方式展示出来你所要操作的列

<el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-setting"
          size="mini"
          @click="visible = true"
          ></el-button
        >
      </el-col>

弹窗所展示的内容 

<el-dialog title="设置表格展示" :visible.sync="visible">
      <transition name="fade">
        <div>
          <div>
            <el-checkbox v-model="showColumn.name">名称</el-checkbox>
            <el-checkbox v-model="showColumn.age">年龄</el-checkbox>
            <el-checkbox v-model="showColumn.city">城市</el-checkbox>
          </div>
          <div style="font-size: 12px;text-align: center;margin-top: 20px;color: red;">取消勾选即可隐藏某列</div>
        </div>
      </transition>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="saveColumn">确 定</el-button>
        </span>
      </template>
    </el-dialog>

在table中增加v-if

<el-table-column label="名称" align="center" prop="name" v-if="showColumn.name"/>

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值