本文實例講述了Vue開發之封裝分頁組件與使用。分享給大家供大家參考,具體如下:
使用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 } // 總條數 }, data() { return { pageSizes: [10, 20, 50, 100], page: { page: 1, limit: 10 } }; }, methods: { // 每頁條數變更 handleSizeChange(val) { this.page.limit = val; this.$emit('pageChange', this.page); }, // 當前頁碼變更 handleCurrentChange(val) { this.page.page = val; this.$emit('pageChange', this.page); } }}</script><style>.pagination { margin: 20px 0;}</style>使用創建的分頁組件
<pagination :total="total" @pageChange="pageChange"></pagination>
// 頁碼切換pageChange(item) { this.searchContent.page = item.page; this.searchContent.limit = item.limit; this.getList();},希望本文所述對大家vue.js程序設計有所幫助。
新聞熱點
疑難解答
圖片精選