亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue實現(xiàn)簡單的分頁功能

 更新時間:2022年03月04日 10:28:23   作者:HLC!  
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)簡單的分頁功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

前端Vue實現(xiàn)分頁功能,供大家參考,具體內(nèi)容如下

我們都知道在spring boot項目中安裝pagehelper可以實現(xiàn)分頁功能,但是在vue中也能在前端實現(xiàn)分頁。

1、首先,在data中定義以下變量:

data() {
? ? return {
? ? ? list: null,
? ? ? listLoading: true,
? ? ? totalPage: 1, // 統(tǒng)共頁數(shù),默認(rèn)為1
?? ??? ??? ?currentPage: 1, //當(dāng)前頁數(shù) ,默認(rèn)為1
?? ??? ??? ?pageSize: 5, // 每頁顯示數(shù)量
? ? ? currentPageData: [], //當(dāng)前頁顯示內(nèi)容
? ? ? headPage: 1
? ? }
? },

2、發(fā)送請求,獲取后端數(shù)據(jù)(list集合)

axios.get('http://192.168.56.1:8081/sel/'+id).then((res) =>{
? ? ? ? console.log(res.data.data )?
? ? ? ? that.list = res.data.data?
? ? ? ? that.listLoading = false

3、根據(jù)返回數(shù)據(jù)list的length來計算data中變量的值:

this.totalPage=Math.ceil(this.list.length / this.pageSize);
? ? ? ? this.totalPage = this.totalPage == 0 ? 1 : this.totalPage;
? ? ? ? this.getCurrentPageData();

4、調(diào)用getCurrentPageData()方法設(shè)置當(dāng)前頁面的數(shù)據(jù)

getCurrentPageData() {
?? ??? ??? ? ? ? ? ? ? ?let begin = (this.currentPage - 1) * this.pageSize;
?? ??? ??? ? ? ? ? ? ? ?let end = this.currentPage * this.pageSize;
?? ??? ??? ? ? ? ? ? ? ?this.currentPageData = this.list.slice(
?? ??? ??? ? ? ? ? ? ? ? ? ?begin,
?? ??? ??? ? ? ? ? ? ? ? ? ?end
?? ??? ??? ? ? ? ? ? ? ?);
?? ??? ??? ? ? ? ? ?},

5、添加按鈕并實現(xiàn)首頁、尾頁、上一頁、下一頁功能:

<input type="button" value="首頁" @click="firstPage">
<input type="button" value="上一頁" @click="prevPage">
<input type="button" value="下一頁" @click="nextPage">
<input type="button" value="尾頁" @click="lastPage">
?//上一頁
prevPage() {
?? ??? ??? ? ? ? ? ? ?
?? ??? ???if (this.currentPage == 1) {
?? ??? ??? ? ?? ?return false;
?? ??? ??? ??} else {
?? ??? ??? ? ? ? this.currentPage--;
?? ??? ??? ? ? ? this.getCurrentPageData();
?? ??? ??? ? ? ?}
?? ??? ??? ? ? ? ? ?},
?? ??? ??? ? ? ? ? ?// 下一頁
?? ??? ??? ? ? ? ? ?nextPage() {

?? ??? ??? ? ? ? ? ? ? ?if (this.currentPage == this.totalPage) {
?? ??? ??? ? ? ? ? ? ? ? ? ?return false;
?? ??? ??? ? ? ? ? ? ? ?} else {
?? ??? ??? ? ? ? ? ? ? ? ? ?this.currentPage++;
?? ??? ??? ? ? ? ? ? ? ? ? ?this.getCurrentPageData();
?? ??? ??? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? },
? ? ? ? ? ? ? //尾頁
? ? ? ? ? ? ? lastPage() {

?? ??? ??? ? ? if (this.currentPage == this.totalPage) {
?? ??? ??? ? ? ? ? ??return false;
?? ??? ??? ? ? ? ? ? ? ?} else {
?? ??? ??? ? ? ? ? ??this.currentPage=this.totalPage;
?? ??? ??? ? ? ? ? ?  this.getCurrentPageData();
? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? } ,
? ? ? ? ? ?//首頁
? ? ? ? ? ? ? firstPage(){
? ? ? ? ? ?  this.currentPage= ?this.headPage;
? ? ? ? ? ?  this.getCurrentPageData();
}

注意!

最后需要修改組件中的data

前端展示:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue v-for中:key中item.id與Index使用的區(qū)別解析

    Vue v-for中:key中item.id與Index使用的區(qū)別解析

    這篇文章主要介紹了Vue v-for中:key中item.id與Index使用的區(qū)別解析,推薦使用【:key="item.id"】而不是將數(shù)組下標(biāo)當(dāng)做唯一標(biāo)識,前者能做到全部復(fù)用,本文給大家詳細(xì)講解,感興趣的朋友跟隨小編一起看看吧
    2024-02-02
  • Vue+Openlayer實現(xiàn)圖形的拖動和旋轉(zhuǎn)變形效果

    Vue+Openlayer實現(xiàn)圖形的拖動和旋轉(zhuǎn)變形效果

    Openlayer具有自己的擴展插件ol-ext,可以用來實現(xiàn)圖形的拖拽、旋轉(zhuǎn)、縮放、拉伸、移動等操作,本文將主要介紹通過Openlayer實現(xiàn)圖形的拖動和旋轉(zhuǎn),需要的同學(xué)可以學(xué)習(xí)一下
    2021-11-11
  • vue中自定義指令(directive)的基本使用方法

    vue中自定義指令(directive)的基本使用方法

    Vue中內(nèi)置了很多的指令,但有時候這些指令并不能滿足我們,或者說我們想為元素附加一些特別的功能,這時候我們就需要用到vue中一個很強大的功能了—自定義指令,這篇文章主要給大家介紹了關(guān)于vue中自定義指令(directive)的基本使用方法,需要的朋友可以參考下
    2021-09-09
  • vue3+ElementPlus使用lang="ts"報Unexpected?token錯誤的解決辦法

    vue3+ElementPlus使用lang="ts"報Unexpected?token錯誤的解決

    最近開發(fā)中遇到了些問題,跟大家分享下,這篇文章主要給大家介紹了關(guān)于vue3+ElementPlus使用lang="ts"報Unexpected?token錯誤的解決辦法,需要的朋友可以參考下
    2023-01-01
  • 基于Vue、Vuex、Vue-router實現(xiàn)的購物商城(原生切換動畫)效果

    基于Vue、Vuex、Vue-router實現(xiàn)的購物商城(原生切換動畫)效果

    這篇文章主要介紹了基于Vue、Vuex、Vue-router實現(xiàn)的購物商城(原生切換動畫)效果,需要的朋友可以參考下
    2018-01-01
  • Vue滾動頁面到指定位置的實現(xiàn)及避坑

    Vue滾動頁面到指定位置的實現(xiàn)及避坑

    這篇文章主要介紹了Vue滾動頁面到指定位置的實現(xiàn)及避坑,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • 在vue中使用防抖和節(jié)流,防止重復(fù)點擊或重復(fù)上拉加載實例

    在vue中使用防抖和節(jié)流,防止重復(fù)點擊或重復(fù)上拉加載實例

    今天小編就為大家分享一篇在vue中使用防抖和節(jié)流,防止重復(fù)點擊或重復(fù)上拉加載實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • 談?wù)刅ue中的nextTick

    談?wù)刅ue中的nextTick

    Vue.nextTick是Vue官方給我們提供的一個API(方法),作用是在下次DOM更新循環(huán)結(jié)束之后執(zhí)行延遲回調(diào)。在修改數(shù)據(jù)之后立即使用這個方法,獲取更新后的DOM
    2021-04-04
  • vue實現(xiàn)鼠標(biāo)經(jīng)過動畫

    vue實現(xiàn)鼠標(biāo)經(jīng)過動畫

    這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)鼠標(biāo)經(jīng)過動畫的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • vue3封裝AES(CryptoJS)前端加密解密通信代碼實現(xiàn)

    vue3封裝AES(CryptoJS)前端加密解密通信代碼實現(xiàn)

    防止數(shù)據(jù)被爬取,前后端傳參接收參數(shù)需要加密處理,使用AES加密,這篇文章主要給大家介紹了關(guān)于vue3封裝AES(CryptoJS)前端加密解密通信代碼實現(xiàn)的相關(guān)資料,需要的朋友可以參考下
    2023-12-12

最新評論