- 硬写版本(没有组件)
- 思路:将返回的列表数据根据每页显示的数量进行切割,分别展示
<div class="table">
<div v-for="(item,index) in currentPageData" :key="index">
{{item.name}}
</div>
</div>
<div class="footer">
<button @click="prevPage()">上一页</button>
<span>第{{currentPage}}页/共{{totalPage}}页</span>
<button @click="nextPage()">下一页</button>
</div>
data () {
return {
mailList:'',
totalPage: 1,
currentPage: 1,
pageSize: 3,
currentPageData: []
}
}
fenye () {
this.totalPage = Math.ceil(this.mailList.length / this.pageSize);
console.log("asdsdsdsdsd->"+this.totalPage)
this.totalPage = this.totalPage == 0 ? 1 : this.totalPage;
this.setCurrentPageData();
console.log("总页面数为--->"+this.totalPage);
},
setCurrentPageData () {
let begin = (this.currentPage - 1) * this.pageSize;
let end = this.currentPage * this.pageSize;
this.currentPageData = this.mailList.slice(begin,end);
},
prevPage () {
console.log(this.currentPage);
if (this.currentPage == 1) return;
this.currentPage--;
this.setCurrentPageData();
},
nextPage () {
if (this.currentPage == this.totalPage)return ;
this.currentPage++;
this.setCurrentPageData();
},
<div class="list-scroll">
<div v-for="(v, i) in computedPageNum" :key="i"
:class="creditId === v.creditId ? 'text-item-active' : 'text-item'"
@click="chooseCard(v)">
{{ `${v.customerName} ${v.phone}` }}
</div>
</div>
<!-- 分页 -->
<el-pagination
background
:total="rightUserList.length"
:pager-count="5"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-size="pageSize"
layout="total,prev,pager,next"
>
</el-pagination>
data () {
return {
rightUserList: [],
totalPage: 1,
currentPage: 1,
pageSize: 10,
}
}
computed: {
computedPageNum() {
return this.rightUserList.slice(
(this.currentPage - 1) * this.pageSize,
this.currentPage * this.pageSize,
);
},
},
methods: {
handleCurrentChange(val) {
this.currentPage = val;
},
}