elementui分页左右滑动
时间: 2023-09-04 13:17:18 浏览: 95
ElementUI并没有提供分页组件左右滑动的功能,但你可以自己实现这个功能。以下是一种实现方式:
1. 使用ElementUI的分页组件,设置`background-color: transparent`,隐藏分页组件的背景色。
2. 在分页组件外部包裹一个容器,设置`overflow-x: auto`,使容器可以水平滚动。
3. 使用JavaScript监听分页组件的`current-change`事件,每当分页组件页码发生变化时,计算当前页码对应的分页按钮的left值,并将容器滚动到该位置即可。
下面是一个示例代码:
```html
<template>
<div class="pagination-container">
<el-pagination class="pagination" :total="100" :current-page.sync="currentPage" :page-size="10" background-color="transparent"></el-pagination>
</div>
</template>
<script>
export default {
data() {
return {
currentPage: 1
}
},
mounted() {
const container = document.querySelector('.pagination-container')
const pagination = document.querySelector('.pagination')
pagination.addEventListener('current-change', () => {
const currentPage = this.currentPage
const button = pagination.querySelector(`.number[data-index="${currentPage - 1}"]`)
if (button) {
const left = button.offsetLeft
container.scrollTo({
left,
behavior: 'smooth'
})
}
})
}
}
</script>
<style>
.pagination-container {
overflow-x: auto;
white-space: nowrap;
}
.pagination {
display: inline-block;
}
</style>
```
注意:这只是一种实现方式,具体实现还需要根据自己的需求进行调整。
阅读全文
相关推荐














