當(dāng)我們向后臺(tái)請(qǐng)求大量數(shù)據(jù)的時(shí)候,并要在頁面展示出來蒙袍,請(qǐng)求的數(shù)據(jù)可能上百條數(shù)據(jù)或者更多的時(shí)候澡罚,并不想在一個(gè)頁面展示概页,這就需要使用分頁功能來去完成了玩郊。
微信圖片_20190712171547.png
1.vue2.0+element-ui實(shí)現(xiàn)一個(gè)分頁功能肢执,element-ui這個(gè)組件特別豐富,分頁中給我提供了一個(gè)Pagination 分頁译红,使用Pagination 快速完成分頁功能
<el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" style="width: 100%">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="id" label="編號(hào)" show-overflow-tooltip width="auto"></el-table-column>
<el-table-column prop="goods_name" label="商品名稱" show-overflow-tooltip width="auto"></el-table-column>
<el-table-column prop="goods_spec" label="商品規(guī)格" width="auto"></el-table-column>
<el-table-column prop="store_name" label="商家名稱" width="auto"></el-table-column>
<el-table-column prop="order_sn" label="訂單編號(hào)" width="auto"></el-table-column>
<el-table-column prop="stock" label="庫存" width="auto">
<template slot-scope="scope">
<el-button type="text" size="mini" v-if="scope.row.stock>0">入庫</el-button>
<el-button type="text" size="mini" style='color: #11b559;' v-if="scope.row.stock<0">出庫</el-button>
</template>
</el-table-column>
<el-table-column prop="ctime" label="日志時(shí)間" width="auto"></el-table-column>
</el-table>
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[5, 10, 20, 40]" //這是下拉框可以選擇的预茄,每選擇一行,要展示多少內(nèi)容
:page-size="pagesize" //顯示當(dāng)前行的條數(shù)
layout="total, sizes, prev, pager, next, jumper"
:total="tableData.length"> //這是顯示總共有多少數(shù)據(jù)侦厚,
</el-pagination>
需要data定義一些耻陕,tableData定義一個(gè)空數(shù)組,請(qǐng)求的數(shù)據(jù)都是存放這里面
data () {
return {
currentPage:1, //初始頁
pagesize:10, // 每頁的數(shù)據(jù)
tableData: []
}
},
methods: {
// 初始頁currentPage假夺、初始每頁數(shù)據(jù)數(shù)pagesize和數(shù)據(jù)data
handleSizeChange: function (size) {
this.pagesize = size;
console.log(this.pagesize) //每頁下拉顯示數(shù)據(jù)
},
handleCurrentChange: function(currentPage){
this.currentPage = currentPage;
console.log(this.currentPage) //點(diǎn)擊第幾頁
},
handleUserList() {
this.$http.get('http://localhost:3000/userList').then(res => { //這是從本地請(qǐng)求的數(shù)據(jù)接口淮蜈,
this.tableData= res.body
})
}
}
以上都是分頁所需的功能,也是自己在自己寫案例中所遇到的已卷,并總結(jié)下方便查看嘿嘿