vue+Element-ui實現(xiàn)分頁效果實例代碼詳解
當我們向后臺請求大量數(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 style="width: 100%;"
: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" //顯示當前行的條數(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é)下方便查看,喜歡的可以關注一下
可以關注一下https://github.com/MrZHLF/vue-admin-system,這個案例還在完善當中,功能還在增加
總結(jié)
以上所述是小編給大家介紹的vue+Element-ui實現(xiàn)分頁效果實例代碼詳解,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- Vue使用Element-UI實現(xiàn)分頁效果全過程
- 利用Vue模擬實現(xiàn)element-ui的分頁器效果
- vue+Element-ui前端實現(xiàn)分頁效果
- vue+Element-ui實現(xiàn)分頁效果
- 在vue和element-ui的table中實現(xiàn)分頁復選功能
- vue + element-ui的分頁問題實現(xiàn)
- vue 基于element-ui 分頁組件封裝的實例代碼
- Vue+element-ui 實現(xiàn)表格的分頁功能示例
- 利用vue和element-ui設置表格內(nèi)容分頁的實例
- vue如何使用element-ui 實現(xiàn)自定義分頁
相關文章
vue3項目+element-plus:時間選擇器格式化方式
這篇文章主要介紹了vue3項目+element-plus:時間選擇器格式化方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
在Vue中使用scoped屬性實現(xiàn)樣式隔離的原因解析
scoped是Vue的一個特殊屬性,可以應用于<style>標簽中的樣式,這篇文章給大家介紹在Vue中,使用scoped屬性為什么可以實現(xiàn)樣式隔離,感興趣的朋友一起看看吧2023-12-12
解決vue3中使用echart報錯:Cannot read properties of&n
在Vue項目中使用Echarts進行數(shù)據(jù)可視化是非常常見的需求,然而有時候在引入Echarts的過程中可能會遇到報錯,本文主要介紹了解決vue3中使用echart報錯:Cannot read properties of undefined (reading ‘type‘),感興趣的可以了解一下2024-01-01
vue中使用iframe嵌入網(wǎng)頁,頁面可自適應問題
這篇文章主要介紹了vue中使用iframe嵌入網(wǎng)頁,頁面可自適應問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue CLI3中使用compass normalize的方法
這篇文章主要介紹了Vue CLI3中使用compass normalize的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05
解決Electron?store的commit和dispatch不好用問題
這篇文章主要介紹了解決Electron?store的commit和dispatch不好用問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-01-01

