element-ui 踩坑 table 表格动态添加筛选属性filters报错

最近在开发过程中,表格的数据列是不固定的,动态展示,一些排序,筛选也是部分表头才有;

所以只能动态渲染表头,以及相关的属性了。如下图

<el-table-column v-for="(head,index) in tableHeader" 
              :key="index" 
              :label="head.label" 
              :prop="head.key"
              :sortable="head.key == 'total_cost'"
              :filters="head.search ? objArr(head.search_data) : null"
              :filter-method="head.search ? filterTag : null"
            >
            <template slot-scope="scope">
                <span v-if="head.key.includes('cost')">{{head.currency+showMoney(scope.row[head.key])}}</span>
                <span v-else>{{scope.row[head.key]}}</span>
            </template>
          </el-table-column>

如果没有filters筛选值的列,属性给值是 flase 或者 ”“,undefined都有问题,值类型不对;和官方API有出入:[Vue warn]: Invalid prop: type check failed for prop "filters". Expected Array, got Boolean with value false.

 

 源码类型定义:

 这里就需要,把不需要筛选的值的列,属性改为 null; 亲测用

具体实例请看我的另一篇文章:https://blog.csdn.net/yufengaotian/article/details/121538032

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值