鸿蒙js开发11:鸿蒙的分页滚动列表视图的实现
Tiechui.Wang 2021-02-01 10:00:00 发布3502 浏览 19 点赞 15 收藏
1.UI的实现效果

2.js业务逻辑部分
import prompt from '@system.prompt';
export default {
data: {
title: 'World',
//建议大家1.本地数据 2.网络数据
//为什么要分页?
// 分页会减少前端加载的负荷,提升页面执行的性能,带来良好的用户体验。
//100条数据,100条数据一次性加载,会带来浪费。
//如果从网络请求数据,分页会减轻服务器的压力和传输的压力。
// 移动端分页 ,加载更多
// 第几页,每页几条 固定10条,数组的内置的方法
listdatas:[0,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],
//第几页
currentnum:1,
//每页几条
fixednum:5,
//分页的数据结果集:
pagelists:[],
text:"加载更多",
flag:false
},
onInit()
{
this.showData(this.currentnum);
},
loaddata()
{
++this.currentnum;
this.showData(this.currentnum);
},
showData(curnum)
{
//36/5=7..1 8页
//三元运算符
let pageSize=this.listdatas.length%this.fixednum==0?
this.listdatas.length/this.fixednum:Math.floor(this.listdatas.length/this.fixednum)+1;
if(curnum>pageSize)
{
prompt.showToast({
message:"用户您好,数据已经到底了",
duration:4000
})
this.text="哥或妹,你好,我已经到底了";
this.flag=true;
}
else
{
//执行分页 第一个参数:从0开始 第二个参数:不到end (end-1)
this.pagelists=this.listdatas.slice(0,curnum*this.fixednum);
}
}
}
3.页面布局
<div class="container">
<div class="topview">
</div>
<div class="contentview">
<list class="listview">
<block for="{{pagelists}}">
<list-item class="listitem">
<text class="tv">{{$item}}</text>
</list-item>
</block>
<list-item>
<div class="{{flag?'lastview1':'lastview'}}" disabled="{{flag}}" onclick="loaddata">
<text class="tv1">{{text}}</text>
</div>
</list-item>
</list>
</div>
<div class="bottomview">
</div>
</div>
4.样式部分
.container {
display: flex;
flex-direction: column;
width: 100%;
height: 1500px;
}
.topview{
width: 100%;
height: 10%;
background-color: powderblue;
position: fixed;
left: 0px;
top:0px;
}
.bottomview{
width: 100%;
height: 10%;
background-color: powderblue;
position: fixed;
left: 0px;
bottom:0px;
}
.contentview{
width: 100%;
height: 100%;
top:150px;
}
.listview{
width: 100%;
height: 100%;
}
.listitem{
width: 100%;
height: 15%;
border-bottom: 5px solid darkgray;
display: flex;
justify-content: center;
align-items: center;
}
.tv{
color: deepskyblue;
font-size: 35px;
font-weight: bold;
font-family: sans-serif;
}
.lastview{
width: 100%;
height: 25%;
background-color: #ff6a06;
display: flex;
justify-content: center;
align-items: center;
}
.tv1{
color: snow;
font-size: 30px;
font-weight: bold;
font-family: sans-serif;
}
.lastview1{
width: 100%;
height: 25%;
background-color: darkgray;
display: flex;
justify-content: center;
align-items: center;
}
5.最终效果

©本站发布的所有内容,包括但不限于文字、图片、音频、视频、图表、标志、标识、广告、商标、商号、域名、软件、程序等,除特别标明外,均来源于网络或用户投稿,版权归原作者或原出处所有。我们致力于保护原作者版权,若涉及版权问题,请及时联系我们进行处理。
分类
其它
标签
鸿蒙
相关推荐
鸿蒙实战项目案例_从零构建完整应用的完整复盘
周正
1324
0鸿蒙生物识别开发:从指纹识别到3D人脸识别的完整指南
周正
1611
0鸿蒙NFC开发实战:从读卡器模式到卡模拟的完整实现
周正
950
0鸿蒙加密存储开发:数据安全保护的完整方案
周正
1361
0鸿蒙应用签名与上架完整流程:从开发到发布的实战指南
周正
2579
0
Tiechui.Wang
我还没有写个人简介......
1091
帖子
0
提问
893
粉丝
最新发布
华为应用市场增长优化师火热认证中
2025-03-10 10:16:02 发布华为应用市场斩获Pocket Gamer2023年移动游戏奖,全球第三大移动应用生态获行业认可
2024-04-27 11:06:07 发布热门推荐