本文實例講述了Vue開發(fā)之封裝分頁組件與使用。分享給大家供大家參考,具體如下:
使用elementui中的el-pagination來封裝分頁組件
pagination.vue:
<template> <div class="pagination"> <el-pagination small class="text-center" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.page" :page-sizes="pageSizes" :page-size="page.limit" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </div> </template> <script> export default { props: { total: { type: Number } // 總條數(shù) }, data() { return { pageSizes: [10, 20, 50, 100], page: { page: 1, limit: 10 } }; }, methods: { // 每頁條數(shù)變更 handleSizeChange(val) { this.page.limit = val; this.$emit('pageChange', this.page); }, // 當(dāng)前頁碼變更 handleCurrentChange(val) { this.page.page = val; this.$emit('pageChange', this.page); } } } </script> <style> .pagination { margin: 20px 0; } </style>
使用創(chuàng)建的分頁組件
<pagination :total="total" @pageChange="pageChange"></pagination>
// 頁碼切換 pageChange(item) { this.searchContent.page = item.page; this.searchContent.limit = item.limit; this.getList(); },
希望本文所述對大家vue.js程序設(shè)計有所幫助。
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com