當我們向后臺請求大量數(shù)據(jù)的時候,并要在頁面展示出來,請求的數(shù)據(jù)可能上百條數(shù)據(jù)或者更多的時候,并不想在一個頁面展示,這就需要使用分頁功能來去完成了。

微信圖片_20190712171547.png
1.vue2.0+element-ui實現(xiàn)一個分頁功能,element-ui這個組件特別豐富,分頁中給我提供了一個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="編號" 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="訂單編號" 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="日志時間" 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" //顯示當前行的條數(shù)
layout="total, sizes, prev, pager, next, jumper"
:total="tableData.length"> //這是顯示總共有多少數(shù)據(jù),
</el-pagination>
需要data定義一些,tableData定義一個空數(shù)組,請求的數(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) //點擊第幾頁
},
handleUserList() {
this.$http.get('http://localhost:3000/userList').then(res => { //這是從本地請求的數(shù)據(jù)接口,
this.tableData= res.body
})
}
}
以上都是分頁所需的功能,也是自己在自己寫案例中所遇到的,并總結(jié)下方便查看嘿嘿