當(dāng)我們向后臺請求大量數(shù)據(jù)的時候,并要在頁面展示出來,請求的數(shù)據(jù)可能上百條數(shù)據(jù)或者更多的時候,并不想在一個頁面展示,這就需要使用分頁功能來去完成了。
目前累計(jì)服務(wù)客戶上1000+,積累了豐富的產(chǎn)品開發(fā)及服務(wù)經(jīng)驗(yàn)。以網(wǎng)站設(shè)計(jì)水平和技術(shù)實(shí)力,樹立企業(yè)形象,為客戶提供成都網(wǎng)站建設(shè)、做網(wǎng)站、網(wǎng)站策劃、網(wǎng)頁設(shè)計(jì)、網(wǎng)絡(luò)營銷、VI設(shè)計(jì)、網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。創(chuàng)新互聯(lián)始終以務(wù)實(shí)、誠信為根本,不斷創(chuàng)新和提高建站品質(zhì),通過對領(lǐng)先技術(shù)的掌握、對創(chuàng)意設(shè)計(jì)的研究、對客戶形象的視覺傳遞、對應(yīng)用系統(tǒng)的結(jié)合,為客戶提供更好的一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進(jìn)步。
1.本次所使用的是vue2.0+element-ui實(shí)現(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搭建的本地?cái)?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) //點(diǎn)擊第幾頁 }, handleUserList() { this.$http.get('http://localhost:3000/userList').then(res => { //這是從本地請求的數(shù)據(jù)接口, this.userList = res.body }) } }
以上都是分頁所需的功能,也是自己在自己寫案例中所遇到的,并總結(jié)下方便查看,喜歡的可以關(guān)注一下
可以關(guān)注一下https://github.com/MrZHLF/vue-admin-system,這個案例還在完善當(dāng)中,功能還在增加
總結(jié)
以上所述是小編給大家介紹的vue+Element-ui實(shí)現(xiàn)分頁效果實(shí)例代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對創(chuàng)新互聯(lián)網(wǎng)站的支持!
本文標(biāo)題:vue+Element-ui實(shí)現(xiàn)分頁效果實(shí)例代碼詳解
瀏覽地址:http://www.chinadenli.net/article32/gepdsc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供云服務(wù)器、微信小程序、商城網(wǎng)站、網(wǎng)站策劃、網(wǎng)站排名、網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)