vue 基于element-ui 分頁組件封裝的實例代碼
更新時間:2018年12月10日 11:59:49 作者:小角色Byme
這篇文章主要介紹了vue 基于element-ui 分頁組件封裝的實例代碼,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
具體代碼如下所示:
<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: {
//每頁展示條數
handleSizeChange(val) {
//事件傳遞
this.$emit('handleSizeChangeSub', val);
},
//當前頁
handleCurrentChange(val) {
//事件傳遞
this.$emit('handleCurrentChangeSub', val);
}
},
// 過濾器設計目的就是用于簡單的文本轉換
filters: {},
// 若要實現更復雜的數據變換,你應該使用計算屬性
computed: {
},
created() {
},
mounted() {},
destroyed() {}
}
</script>
<style lang="scss" type="text/css" scoped>
</style>
調用
// 分頁
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)都會有很多的列表,有列表就相應的要用到分頁,根據項目中寫的幾個分頁寫一下我對分頁的理解,就當是學習筆記了。
這是Element-ui提供的完整的例子
<template> <div class="block">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[100, 200, 300, 400]"http://這事下拉框可以選擇的,選擇一夜顯示幾條數據
:page-size="100" //這是當前煤業(yè)顯示的條數
layout="total, sizes, prev, pager, next, jumper"
:total="400" //這個是總共有多少條數據,把后臺獲取到的數據總數復制給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>
總結
以上所述是小編給大家介紹的vue 基于element-ui 分頁組件封裝的實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
Vue中this.$nextTick()方法的使用及代碼示例
$nextTick()是Vue.js框架中的一個方法,它主要用于DOM操作,當我們修改Vue組件中的數據時,Vue.js會在下次事件循環(huán)前自動更新視圖,并異步執(zhí)行$nextTick()中的回調函數,本文主要介紹了Vue中this.$nextTick()方法的使用及代碼示例,需要的朋友可以參考下2023-05-05
Vue + Element-ui的下拉框el-select獲取額外參數詳解
這篇文章主要介紹了Vue + Element-ui的下拉框el-select獲取額外參數詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-08-08

