本文主要实现数据的分页加载效果
视图及样式:
效果图:


业务逻辑层:
import prompt from '@system.prompt';
export default {
data: {
listdatas:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45],
currentpage:1,
number:10,
pagedatas:[],
more:false,
text:"加载更多"
},
onInit(){
this.loaddata(this.currentpage);
},
loadmore(){
++this.currentpage;
this.loaddata(this.currentpage);
},
loaddata(currentnum){
let pageNumber = this.listdatas.length%this.number==0?
this.listdatas.length/this.number:Math.floor(this.listdatas.length/this.number)+1;
if(currentnum>pageNumber){
prompt.showToast({
message:"数据已经到底了"
});
this.text = "数据已经到底了";
this.more = true;
}else{
this.pagedatas = this.listdatas.slice(0,currentnum*this.number);
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
如果能把源代码打个包作为附件,那就更好啦^_^