vue.js分页

<div class="contanier">
//绑定显示的数据容器
</div>
<div class="pagination">
            <div class="pages-box">
                <div class="pages-prev" @click="pagePrev()">
                    <svg-icon icon-class="up" class="fillcolor" :class="{'disabled': currentPage === 1 }" />
                </div>
                <div class="pages">{{ currentPage }}/{{ pageCount }}</div>
                <div class="pages-next" @click="pageNext()">
                    <svg-icon icon-class="down" class="fillcolor" :class="{'disabled': currentPage === pageCount}" />
                </div>
            </div>
        </div>
data() {
        return {
           
            labourOption: {},
            showPage: [], // 每页展示的内容
            pageSize: 8, // 每页要展示数据条数
            // 总页数
            pageCount: '',
            pageItems: [],
            // 当前页
            currentPage: 1,
            colorData:['#EB9AFF','#25A54F','#2CC6EA','#0263FF','#FB6E52','#8256E8','#FF7E00','#FFC655'],
            seriesData: [],
           }
        }
 created() {
        // 求总页数,Math.ceil()方法 可以对数进行上舍入
        // this.pageCount = Math.ceil(this.seriesData.length / this.pageSize)
        // this.curpage(this.currentPage)
        this.getData()
   
    },

 

methods:{
// 获取数据
        getData() {
            chartCount(this.queryParams).then(res => {
               // 获取数据
                this.seriesData = res.data.organization
               /* // 替换需要的key名字
                this.seriesData && this.seriesData.forEach((item, index) => {
                    this.seriesData[index] = JSON.parse(
                        JSON.stringify(this.seriesData[index])
                            .replace(/statisCount/g, 'value')
                            .replace(/typeName/g, 'name')
                    )
                    // this.seriesData.push({
                    //     value: i.statisCount,
                    //     name: i.typeName
                    // })
                })*/
                this.getOptions()
            })
        },
 getOptions() {
            this.pageCount = Math.ceil(this.seriesData.length / this.pageSize)
            let list = (this.currentPage - 1) * this.pageSize // 每去一组数据的第一个索引
            this.showPage = this.seriesData.slice(list, list + this.pageSize) // 从总数据中取出每页的数据

            /* this.showPage = this.seriesData.slice(
                (this.currentPage - 1) * this.pageSize, this.currentPage * this.pageSize
            )*/
        },
// 翻页传值
        curpage(num) {
            this.currentPage = num // 当前页
        },
        pagePrev() {
            if (this.currentPage != 1) {
                this.currentPage--
                this.curpage(this.currentPage)
            }
            this.getOptions()
        },
        pageNext() {
            if (this.currentPage < this.pageCount) {
                this.currentPage++
                this.curpage(this.currentPage)
            }
            this.getOptions()
        }
}
<style lang="scss" scoped>
    .pagination{
        width: 100%;
        position: absolute;
        bottom: 0;
        display: flex;
        justify-content: flex-start;
        padding: 5px 0;
        .pages-box{
            width: 50%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            .pages{
                margin: 0 5px;
                color: #00CAFF;
            }
        }
        .fillcolor{
            fill: #2A72FF;
        }
        .disabled{
            fill: #052666 ;
        }
    }
</style>

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值