html
<div class="container">
<div class="contentview">
<block for="{{listdata}}">
<div class="lineview">
<text>{{$item}}</text>
</div>
</block>
</div>
<div class="operatorview" onclick="loadmore" disabled="{{flag}}">
<text>{{loadtext}}</text>
</div>
</div>
css
.container {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
}
.contentview {
display: flex;
overflow: scroll;
width: 100%;
flex-direction: column;
}
.lineview {
width: 100%;
height: 10%;
border-bottom: 1px solid black;
display: flex;
justify-content: center;
align-items: center;
background-color: blue;
}
.operatorview {
height: 35vp;
width: 100%;
position: fixed;
bottom: 0;
left: 0;
background-color: yellow;
display: flex;
justify-content: center;
align-items: center;
}
listdata:[],//每次存放10条数据
//使用JavaScript原生api方法 Slice(startnum , endnum)截取十条数据
this.listdata = this.arrs.slice(0,this.currentpage*PAGE_NUM);
js
import prompt from '@system.prompt';
const PAGE_NUM=10;
export default {
data: {
arrs:[],
listdata:[],
currentpage:1,
loadtext:"加载更多",
flag:false,
},
onInit(){
for(let i=0;i<50;i++){
this.arrs.push("第"+i+"项");
}
this.listdata = this.arrs.slice(0,this.currentpage*PAGE_NUM);
},
loadmore(){
this.currentpage ++;
prompt.showToast({
message:"加载的是第"+this.currentpage+"页"
})
let maxSize = this.arrs.length%PAGE_NUM == 0 ?
this.arrs.length/PAGE_NUM:parseInt(this.arrs.length/PAGE_NUM)+1;
console.log("总共"+this.arrs.length+"页");
if (this.currentpage > maxSize) {
prompt.showToast({
message:"没有更多数据了"
})
this.loadtext = '已经到底了';
this.flag = true;
}
else{
this.listdata = this.arrs.slice(0,this.currentpage*PAGE_NUM)
}
}
}