antd vue 中表格得customRender渲染中使用过滤器filters

15 篇文章 1 订阅

antd vue 中表格得customRender渲染中使用过滤器filters

问题描述

在业务开发中,有时候对于时间处理,可能不是全部都要时分秒得显示,这里我使用vue得过滤器,然后就出现一个毛病,我是在表头定义得时候,直接使用得customRender渲染得,普通得过滤器是通过 | 来实现,那么这里怎么处理呢

问题解决

使用-> this.$options.filters.过滤器名字(参数)

代码

  • 全局定义过滤器
	import Vue from 'vue'
	import moment from 'moment'
	// 定义一个全局过滤器
	Vue.filter('minFormat', function (dataStr, pattern = 'YYYY-MM-DD HH:mm') {
	  return moment(dataStr).format(pattern)
	})
  • 使用
// 这里是表头定义
tableColumns: [
     {
       title: '更新时间',
       dataIndex: 'updatedTime',
       customRender: (text) => {
         return (
           <div>
             { this.$options.filters.minFormat(text) } // 在这里直接如此调用即可,有点像调用方法得样子
           </div>
         )
       }
     }
   ]

效果

在这里插入图片描述

  • 5
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,可以得知该问题是关于如何使用Antd Vue组件库的动态表格scroll的。下面是一个简单的例子,演示如何使用Antd Vue的Table组件实现动态表格scroll: ```vue template> <a-table :columns="columns" :data-source="dataList" :scroll="{ x: '100%', y: `calc(100vh - ${tableTop+280+'px'})` }" :pagination="false"> <template slot="title"> <div class="table-title">Table Title</div> </template> </a-table> </template> <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', key: 'name', }, { title: 'Age', dataIndex: 'age', key: 'age', }, { title: 'Address', dataIndex: 'address', key: 'address', }, ], dataList: [ { key: '1', name: 'John Brown', age: 32, address: 'New York No. 1 Lake Park', }, { key: '2', name: 'Jim Green', age: 42, address: 'London No. 1 Lake Park', }, { key: '3', name: 'Joe Black', age: 32, address: 'Sidney No. 1 Lake Park', }, // ... more data ], tableTop: 0, tableList: [], }; }, mounted() { const a = document.querySelector('.ant-table-header'); this.tableList = [a.clientHeight, a.clientHeight]; this.tableTop = this.tableList[0]; }, watch: { columns() { setTimeout(() => { const a = document.querySelector('.ant-table-header'); this.tableList.push(a.clientHeight); this.tableList.splice(0, 1); this.tableTop = this.tableList[1]; }, 10); }, }, }; </script> ``` 在上面的代码,我们使用Antd Vue的Table组件,并设置了columns和dataList属性来定义表格的列和数据。我们还设置了scroll属性来控制表格的滚动,其x属性设置为'100%',表示表格宽度自适应,y属性设置为`calc(100vh - ${tableTop+280+'px'})`,表示表格高度自适应。我们还使用了mounted和watch属性来动态计算表头高度和更新表格高度。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值