具體代碼如下所示:
<template> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total" style="float:right;"> </el-pagination></template><script type="text/ecmascript-6">export default { components: { }, data() { return { } }, props: { pageSize: { type: Number, default: 10 }, total: { type: Number, default: 1 } }, watch: { }, methods: { //每頁展示條數(shù) handleSizeChange(val) { //事件傳遞 this.$emit('handleSizeChangeSub', val); }, //當前頁 handleCurrentChange(val) { //事件傳遞 this.$emit('handleCurrentChangeSub', val); } }, // 過濾器設(shè)計目的就是用于簡單的文本轉(zhuǎn)換 filters: {}, // 若要實現(xiàn)更復(fù)雜的數(shù)據(jù)變換,你應(yīng)該使用計算屬性 computed: { }, created() { }, mounted() {}, destroyed() {}}</script><style lang="scss" type="text/css" scoped></style>
調(diào)用
// 分頁import pages from 'components/common/pages/pages'components: { pages },<pages :total="total" :page-size="pageSize" @handleSizeChangeSub="handleSizeChangeFun" @handleCurrentChangeSub="handleCurrentChangeFun"></pages>handleSizeChangeFun(v) { this.pageSize = v; this._enterpriseList(); //更新列表},handleCurrentChangeFun(v) { //頁面點擊 this.pageNum = v; //當前頁 this._enterpriseList(); //更新列表}
補充:下面看下Element-ui組件--pagination分頁
一般寫后臺系統(tǒng)都會有很多的列表,有列表就相應(yīng)的要用到分頁,根據(jù)項目中寫的幾個分頁寫一下我對分頁的理解,就當是學(xué)習(xí)筆記了。
這是Element-ui提供的完整的例子
<template> <div class="block"> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[100, 200, 300, 400]"http://這事下拉框可以選擇的,選擇一夜顯示幾條數(shù)據(jù) :page-size="100" //這是當前煤業(yè)顯示的條數(shù) layout="total, sizes, prev, pager, next, jumper" :total="400" //這個是總共有多少條數(shù)據(jù),把后臺獲取到的數(shù)據(jù)總數(shù)復(fù)制給total就可以了> </el-pagination> </div></template><script> export default { methods: { handleSizeChange(val) { console.log(`每頁 ${val} 條`); }, handleCurrentChange(val) { console.log(`當前頁: ${val}`); } }, data() { return { total:'0', currentPage: 4 }; } }</script>
以下是我自己在項目中用到的分頁
<div style="float:right;margin-top:20px;"> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4" :page-sizes="[5, 10, 20, 30]" :page-size="pageSize" //寫代碼時忘記把pageSize賦值給:page-size了, layout="total, sizes, prev, pager, next, jumper" :total="totalCount"> </el-pagination></div>
總結(jié)
以上所述是小編給大家介紹的vue 基于element-ui 分頁組件封裝的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對武林網(wǎng)網(wǎng)站的支持!
新聞熱點
疑難解答