Ant Design Vue(a-table)固定表头三行代码

第一步只需要找到相对应类名

第二步就是通过类名粘性定位控制

/deep/ .ant-table-thead{
  position:sticky;
  top:0px;
  z-index:1;
}

第三步大功告成!!!

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
根据提供的引用内容,我们可以使用vue3-seamless-scroll和a-table来实现固定表头的效果。具体步骤如下: 1.安装vue3-seamless-scroll插件 ```shell npm install vue-seamless-scroll --save ``` 2.在main.js文件中引入vue3-seamless-scroll插件 ```javascript import Vue from 'vue' import VueSeamlessScroll from 'vue-seamless-scroll' Vue.use(VueSeamlessScroll) ``` 3.在template中使用vue3-seamless-scroll组件,并将a-table作为子组件嵌套在其中。需要注意的是,需要将a-table的高度设置为固定值,并将其放在一个div中,以便于在滚动时固定表头。 ```html <template> <vue-seamless-scroll :speed="100" :pause-on-hover="true"> <div class="scroll-table" ref="scrollTable"> <a-table :columns="columns" :data-source="data" :scroll="{ y: 300 }"> <template #scroll-body="{ scrollBodyRef }"> <div class="table-body" ref="tableBody"> <a-table :columns="columns" :data-source="data" :scroll="{ y: 0 }"></a-table> </div> </template> </a-table> </div> </vue-seamless-scroll> </template> ``` 4.在script中定义columns和data,用于渲染a-table。 ```javascript <script> export default { data() { return { columns: [ { title: 'Name', dataIndex: 'name', fixed: 'left', width: 100 }, { title: 'Age', dataIndex: 'age', width: 100 }, { title: 'Address', dataIndex: 'address', width: 200 }, { title: 'Action', key: 'action', fixed: 'right', width: 100, slots: { customRender: 'action' } } ], data: [ { 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' }, { key: '4', name: 'Disabled User', age: 99, address: 'Sidney No. 1 Lake Park' } ] } }, mounted() { this.$refs.scrollTable.addEventListener('scroll', (event) => { this.adjustTable(event) }) }, methods: { adjustTable(event) { const tableHeader = this.$refs.tableBody.querySelector('.ant-table-header') tableHeader.style.transform = `translateX(-${event.target.scrollLeft}px)` } } } </script> ``` 5.在style中定义样式,使得表头固定在顶部。 ```css <style> .scroll-table { height: 300px; overflow: auto; position: relative; } .table-body { height: 0; overflow: hidden; } .ant-table-header { position: sticky; top: 0; z-index: 1; background-color: #fff; } </style> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值