vue+Element-ui實現(xiàn)分頁效果
當(dāng)我們向后臺請求大量數(shù)據(jù)的時候,并要在頁面展示出來,請求的數(shù)據(jù)可能上百條數(shù)據(jù)或者更多的時候,并不想在一個頁面展示,這就需要使用分頁功能來去完成了。
1.本次所使用的是vue2.0+element-ui實現(xiàn)一個分頁功能,element-ui這個組件特別豐富,分頁中給我提供了一個Pagination 分頁,使用Pagination 快速完成分頁功能
最終效果展示
<div class='deit'> <div class='crumbs'> <el-breadcrumb separator='/'> <el-breadcrumb-item><i class='el-icon-date'></i> 數(shù)據(jù)管理</el-breadcrumb-item> <el-breadcrumb-item>用戶列表</el-breadcrumb-item> </el-breadcrumb> <div class='cantainer'> <el-table :data='userList.slice((currentPage-1)*pagesize,currentPage*pagesize)' //對數(shù)據(jù)請求的處理,最為重要的一句話 > <el-table-column type='index' width='50'> </el-table-column> <el-table-column label='日期' prop='date' width='180'> </el-table-column> <el-table-column label='用戶姓名' prop='name' width='180'> </el-table-column> <el-table-column label='郵箱' prop='email' width='180'> </el-table-column> <el-table-column label='地址' prop='address' width='200'> </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='userList.length'> //這是顯示總共有多少數(shù)據(jù), </el-pagination> </div> </div></div>
需要data定義一些,userList定義一個空數(shù)組,請求的數(shù)據(jù)都是存放這里面
data () { return {currentPage:1, //初始頁pagesize:10, // 每頁的數(shù)據(jù)userList: [] } },
對一些數(shù)據(jù),方法處理,數(shù)據(jù)的來源是自己通過json-server搭建的本地數(shù)據(jù),通過vue-resource請求數(shù)據(jù),
created() { this.handleUserList() }, 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.userList = res.body }) } }
以上都是分頁所需的功能,也是自己在自己寫案例中所遇到的,并總結(jié)下方便查看,喜歡的可以關(guān)注一下
關(guān)于vue.js的學(xué)習(xí)教程,請大家點擊專題vue.js組件學(xué)習(xí)教程、Vue.js前端組件學(xué)習(xí)教程進行學(xué)習(xí)。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 不要在HTML中濫用div2. HTML5實戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)3. CSS百分比padding制作圖片自適應(yīng)布局4. React優(yōu)雅的封裝SvgIcon組件示例5. Vue如何使用ElementUI對表單元素進行自定義校驗及踩坑6. vue前端RSA加密java后端解密的方法實現(xiàn)7. CSS清除浮動方法匯總8. Electron調(diào)用外接攝像頭并拍照上傳實現(xiàn)詳解9. HTTP協(xié)議常用的請求頭和響應(yīng)頭響應(yīng)詳解說明(學(xué)習(xí))10. TypeScript實現(xiàn)十大排序算法之歸并排序示例詳解
