ant design Vue 純前端實(shí)現(xiàn)分頁問題
ant design Vue純前端實(shí)現(xiàn)分頁功能
(有選擇的話最好讓后端分頁,前端分頁可能會(huì)有問題,為了性能,盡量不要前端分頁)
自己想的一個(gè)簡(jiǎn)單方法
通過頁碼改變事件,每頁數(shù)據(jù)個(gè)數(shù)改變事件,獲取改變后的頁碼,每頁條數(shù),獲取數(shù)組中對(duì)應(yīng)的數(shù)據(jù)。
代碼如下:
html:
<template>
? <div>
? ? <h3>學(xué)習(xí)文件</h3>
? ? <div class="videoMain" v-if="dataSourceList.length">
? ? ? <div class="videoBox" v-for="item in dataSourceList" :key="item.index">
? ? ? ? <a-tooltip placement="top">
? ? ? ? ? <template slot="title">
? ? ? ? ? ? {{item.name}}
? ? ? ? ? </template>
? ? ? ? ? <a class="ellipsis" :href="item.VUrl" rel="external nofollow" >{{item.name}}</a>
? ? ? ? </a-tooltip>
? ? ? </div>
? ? </div>
? ? <!-- 分頁 -->
? ? <div style="margin-top: 20px;" v-if="dataSourceList.length">
? ? ?<a-pagination size="small"?
? ? ? ? :total="ipagination.total"?
? ? ? ? v-model="ipagination.current"
? ? ? ? show-size-changer?
? ? ? ? show-quick-jumper?
? ? ? ? :page-size-options="ipagination.pageSizeOptions"
? ? ? ? :page-size="ipagination.pageSize"
? ? ? ? @change="pageChange"
? ? ? ? @showSizeChange="onShowSizeChange"
? ? ? ? :show-total="ipagination.showTotal" />
? ? </div>
? ? <div class="nullError" v-else>
? ? ? <p>暫無文件</p>
? ? </div>
? </div>
</template>data:
data() {
? ? ? return {
? ? ? ? description: '文件列表組件',
? ? ? ? dataSource:[], //獲取的數(shù)據(jù)
? ? ? ? dataSourceList:[],//分頁后的數(shù)據(jù)
? ? ? ? /* 分頁參數(shù) */
? ? ? ? ipagination:{
? ? ? ? ? current: 1,//當(dāng)前頁數(shù)
? ? ? ? ? pageSize: 6,
? ? ? ? ? pageSizeOptions: ['6', '10','20','30', '50'],
? ? ? ? ? showTotal: (total, range) => {
? ? ? ? ? ? return range[0] + "-" + range[1] + " 共" + total + "條"
? ? ? ? ? },
? ? ? ? ? showQuickJumper: true,
? ? ? ? ? showSizeChanger: true,
? ? ? ? ? total: 0
? ? ? ? },
? ? ? };
? ? },獲取數(shù)據(jù):
created() {
?? ?this.loadData(); ///獲取數(shù)據(jù)的方法
},methods:
loadData(){
? ? ? ? getAction(this.URL).then((res)=>{
? ? ? ? ? if(res.success){
? ? ? ? ? ? this.dataSource = res.result.records;
? ? ? ? ? }else{
? ? ? ? ? ? this.$message.error(res.message)
? ? ? ? ? }
? ? ? ? }).finally(()=>{
? ? ? ? //獲取數(shù)據(jù)后調(diào)用一次分頁方法
? ? ? ? ? this.changeData(param.current,param.pageSize);//獲取數(shù)據(jù)后調(diào)用一次分頁方法
? ? ? ? })
? ? ? },
? ? ? // 頁碼改變的回調(diào),參數(shù)是改變后的頁碼及每頁條數(shù)
? ? ? pageChange(page,pageSize){
? ? ? ? this.changeData(page,pageSize);
? ? ? },
? ? ? // 下拉選項(xiàng)改變, 參數(shù)是改變后的頁碼及每頁條數(shù)
? ? ? onShowSizeChange(current, pageSize) {
? ? ? ? this.ipagination.pageSize = pageSize;
? ? ? ? this.changeData(current,pageSize);
? ? ? },
? ? ? // 分頁改變時(shí),獲取對(duì)應(yīng)的數(shù)據(jù),動(dòng)態(tài)改變數(shù)據(jù)
? ? ? changeData(page,pageSize){
? ? ? ? var p = (page - 1)*pageSize;
? ? ? ? var pSize = page*pageSize;
? ? ? ? var dataSourceList = [];
? ? ? ? this.dataSource.forEach((item,index)=>{
? ? ? ? ? if(p<= index && index< pSize){
? ? ? ? ? ? dataSourceList.push(item)
? ? ? ? ? }
? ? ? ? })
? ? ? ? this.dataSourceList = dataSourceList;
? ? ? }主要是后面幾個(gè)方法,changeData是改變的具體方法。
方式二
用computed 屬性計(jì)算
? computed: {
? ? TableData() {
? ? ? return this.teacherList.slice(
? ? ? ? (this.pagination.page - 1) * this.pagination.limit,
? ? ? ? this.pagination.page * this.pagination.limit
? ? ? );
? ? },
? },ant design vue中分頁器的使用注意事項(xiàng)
1. 輸入defaultPageSize: '5',pageSizeOptions: ['5', '10', '15', '20']等時(shí),需要是String的形式,否則只會(huì)展示具體數(shù)字,而不是以5條/頁的形式

正確樣式

錯(cuò)誤樣式
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue watch監(jiān)聽數(shù)據(jù)變化的案例詳解
監(jiān)聽數(shù)據(jù)變化,在Vue中是通過偵聽器來實(shí)現(xiàn)的,你也可以將它理解為監(jiān)聽器,時(shí)刻監(jiān)聽某個(gè)數(shù)據(jù)的變化,本文將通過代碼示例為大家詳細(xì)的介紹一下vue watch如何監(jiān)聽數(shù)據(jù)變化,需要的朋友可以參考下2023-07-07
vue.js項(xiàng)目 el-input 組件 監(jiān)聽回車鍵實(shí)現(xiàn)搜索功能示例
今天小編就為大家分享一篇vue.js項(xiàng)目 el-input 組件 監(jiān)聽回車鍵實(shí)現(xiàn)搜索功能示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08
vue+jquery+lodash實(shí)現(xiàn)滑動(dòng)時(shí)頂部懸浮固定效果
這篇文章主要為大家詳細(xì)介紹了vue+jquery+lodash實(shí)現(xiàn)滑動(dòng)時(shí)頂部懸浮固定效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-04-04
vue使用el-upload實(shí)現(xiàn)文件上傳的實(shí)例代碼
這篇文章主要為大家詳細(xì)介紹了vue使用el-upload實(shí)現(xiàn)文件上傳,文中示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,感興趣的小伙伴們可以參考一下2024-01-01

