Vue+Element-U實(shí)現(xiàn)分頁(yè)顯示效果
本文實(shí)例為大家分享了Vue+Element-U實(shí)現(xiàn)分頁(yè)顯示效果的具體代碼,供大家參考,具體內(nèi)容如下
當(dāng)我們從后端返回的數(shù)據(jù)量很大,并且根據(jù)需求我們需要將返回的數(shù)據(jù)全部都顯示在頁(yè)面中,默認(rèn)情況下會(huì)把所有的數(shù)據(jù)全部顯示在一個(gè)頁(yè)面,這樣非常影響視覺(jué)和頁(yè)面的使用,所以需要使用分頁(yè)
我這次使用的是Vue4.0 + Element-UI組件,Element-UI庫(kù)非常的豐富,它提供了一個(gè)分頁(yè)組件 Pagination
展示效果:這個(gè)是獲取兩個(gè)時(shí)間段的上機(jī)記錄

HTML部分:
<el-card> <div class="block"> <span style="left:-100px; position:relative"> <span class="demonstration" style='margin-right:10px'> 開(kāi)始日期 </span> <el-date-picker v-model="value1" type="datetime" placeholder="選擇日期" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd hh:mm:ss"> </el-date-picker> </span> <span style="left:-70px; position:relative"> <span class="demonstration" style='margin-right:10px'> 截止日期</span> <el-date-picker v-model="value2" type="datetime" placeholder="選擇日期" value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd hh:mm:ss"> </el-date-picker> </span> <el-button type="primary" style="left:-40px;position:relative" @click="lineCrodList"> 搜索 </el-button> </div> <el-table :data="lineData" style="width: 80%;left:60px;top:20px"> <el-table-column prop="onTime" label="上機(jī)時(shí)間"> </el-table-column> <el-table-column prop="downTime" label="下機(jī)時(shí)間"> </el-table-column> <el-table-column prop="spendCash" label="花費(fèi)時(shí)間"> </el-table-column> <el-table-column prop="spendCash" label="花費(fèi)金額"> </el-table-column> </el-table> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[1, 2, 5, 10]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination> </el-card>
分頁(yè)控件的代碼如下:
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[1, 2, 5, 10]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
解析:
@size-change:這個(gè)是一個(gè)方法,當(dāng)在頁(yè)面改變每頁(yè)顯示的條數(shù)時(shí),會(huì)觸發(fā)該方法

@current-change:點(diǎn)擊當(dāng)前頁(yè)改變的時(shí)候會(huì)觸發(fā)該方法

:current-page:當(dāng)前頁(yè)數(shù)
:page-sizes:個(gè)數(shù)選擇器的選項(xiàng)設(shè)置

:page-size:每頁(yè)顯示的條數(shù)
:total:總數(shù)據(jù)數(shù)量
JS代碼:
<script>
export default {
data () {
return {
value1: '',
value2: '',
lineData: [],
username: '',
total: 0, //實(shí)現(xiàn)動(dòng)態(tài)綁定
pageSize: 2,
currentPage: 1,
}
},
methods: {
//當(dāng)改變每頁(yè)顯示條數(shù)的選擇器時(shí)會(huì)觸發(fā)的事件
handleSizeChange (size) {
// 每頁(yè)顯示的數(shù)量是我們選擇器選中的值size
this.pageSize = size;
console.log(this.pageSize);//每頁(yè)下拉顯示數(shù)據(jù)
this.lineCrodList();
},
//當(dāng)改變當(dāng)前頁(yè)數(shù)的時(shí)候觸發(fā)的事件
handleCurrentChange (currentPage) {
this.currentPage = currentPage;
console.log(this.currentPage);//點(diǎn)擊第幾頁(yè)
this.lineCrodList();
},
//獲取用戶上機(jī)記錄的信息分頁(yè)
async lineCrodList () {
//調(diào)用 獲取total數(shù)據(jù)的方法
this.counttotal();
await this.$http.post('/Line/SelectInfo', {
userName: this.username,
onTime: this.value1,
downTime: this.value2,
spendCash: 0,
start: (this.currentPage-1)* this.pageSize,
pageSize: this.pageSize
}).then(res => {
this.lineData = res.data;
console.log(res.data)
})
},
//獲取用戶總條數(shù)
async counttotal () {
await this.$http.post('/Line/selectTotal', {
userName: this.username,
onTime: this.value1,
downTime: this.value2,
}).then(res => {
this.total = res.data;
})
}
我們前端請(qǐng)求的時(shí)候需要給后端發(fā)送start 和 pageSize 這兩個(gè)參數(shù) 因?yàn)榫唧w的數(shù)據(jù)是后端通過(guò)數(shù)據(jù)庫(kù)來(lái)搜索的
后臺(tái)Sql語(yǔ)句,其他層的代碼我就不在這里列出

可以看到 limit i,n
i:表示查詢結(jié)果的索引值
n:為查詢結(jié)果的返回?cái)?shù)量
i 和 n之間用逗號(hào)分隔
例子:
#分頁(yè)顯示新聞數(shù)據(jù),每頁(yè)顯示兩條,這里顯示第一頁(yè) SELECT id,title,author,createdate FROM news_detail LIMIT 0,2 #分頁(yè)顯示新聞數(shù)據(jù),每頁(yè)顯示兩條,這里顯示第二頁(yè) SELECT id,title,author,createdate FROM news_detail LIMIT 2,2 #分頁(yè)顯示新聞數(shù)據(jù),每頁(yè)顯示兩條,這里顯示第三頁(yè) SELECT id,title,author,createdate FROM news_detail LIMIT 4,2 #公用的分頁(yè)sql #第二個(gè)數(shù):分頁(yè)后每頁(yè)顯示幾條新聞(頁(yè)面容量) pageSize #第一個(gè)數(shù):從第幾條數(shù)據(jù)開(kāi)始顯示(當(dāng)前頁(yè)碼pageNo-1)*pageSize SELECT id,title,author,createdate FROM news_detail LIMIT (pageNo-1)*pageSize,pageSize
我把(pageNo-1)*pageSize 寫到了前端,所以就無(wú)需在后端重復(fù)寫

# 查詢8條數(shù)據(jù),索引從5到12,第6條記錄到第13條記錄 select * from t_user limit 5,8;
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 利用vue + element實(shí)現(xiàn)表格分頁(yè)和前端搜索的方法
- Vue+element-ui 實(shí)現(xiàn)表格的分頁(yè)功能示例
- vue + element-ui的分頁(yè)問(wèn)題實(shí)現(xiàn)
- 利用vue和element-ui設(shè)置表格內(nèi)容分頁(yè)的實(shí)例
- vue+element tabs選項(xiàng)卡分頁(yè)效果
- Vue+ElementUI table實(shí)現(xiàn)表格分頁(yè)
- vue+elementUI組件table實(shí)現(xiàn)前端分頁(yè)功能
- vue+Element-ui前端實(shí)現(xiàn)分頁(yè)效果
- vue仿element實(shí)現(xiàn)分頁(yè)器效果
- vue+Element實(shí)現(xiàn)分頁(yè)效果
相關(guān)文章
vue項(xiàng)目中輪詢狀態(tài)更改方式(鉤子函數(shù))
這篇文章主要介紹了vue項(xiàng)目中輪詢狀態(tài)更改方式(鉤子函數(shù)),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
vue init webpack myproject構(gòu)建項(xiàng)目 ip不能訪問(wèn)的解決方法
下面小編就為大家分享一篇vue init webpack myproject構(gòu)建項(xiàng)目 ip不能訪問(wèn)的解決方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
vue如何使用el-table遍歷循環(huán)表頭和表體數(shù)據(jù)
這篇文章主要介紹了vue如何使用el-table遍歷循環(huán)表頭和表體數(shù)據(jù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
詳解Vue.js搭建路由報(bào)錯(cuò) router.map is not a function
這篇文章主要介紹了詳解Vue.js搭建路由報(bào)錯(cuò) router.map is not a function,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-06-06
vue-cli創(chuàng)建項(xiàng)目及項(xiàng)目結(jié)構(gòu)解析
上一篇我們安裝了vue-cli,接下來(lái)我們就使用該腳手架進(jìn)行創(chuàng)建項(xiàng)目,這篇文章主要介紹了vue-cli創(chuàng)建項(xiàng)目以及項(xiàng)目結(jié)構(gòu)的相關(guān)資料,需要的朋友可以參考下面文章的具體內(nèi)容2021-10-10
Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說(shuō)明
這篇文章主要介紹了Vuex中this.$store.commit()和this.$store.dispatch()區(qū)別說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-04-04
vue+el使用this.$confirm,不能阻斷代碼往下執(zhí)行的解決
這篇文章主要介紹了vue+el使用this.$confirm,不能阻斷代碼往下執(zhí)行的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue實(shí)現(xiàn)contenteditable元素雙向綁定的方法詳解
contenteditable是所有HTML元素都有的枚舉屬性,表示元素是否可以被用戶編輯。本文將詳細(xì)介紹如何實(shí)現(xiàn)contenteditable元素的雙向綁定,需要的可以參考一下2022-05-05
詳解vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router.push()
本篇文章主要介紹了vue-router 2.0 常用基礎(chǔ)知識(shí)點(diǎn)之router.push(),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05

