赞
踩
Page(Object object)
,注册小程序的一个页面,该函数接收一个对象类型的参数,该对象包含如下属性:
onPullDownRefresh
,下拉刷新时触发。注意哈,只有在全局配置或者页面配置中开启enablePullDownRefresh时,才会生效,即"enablePullDownRefresh": true
。onReachBottom
,上拉触底时触发代码涉及的文件有:
{
"pages": [
"pages/home/home"
],
"window": {
"navigationBarBackgroundColor": "#0149af",
"navigationBarTitleText": "首页",
"navigationBarTextStyle": "white"
},
"style": "v2",
"sitemapLocation": "sitemap.json"
}
<view class="homeContainer">
<view class="content" wx:for="{{contentList}}" wx:key="{{index}}">{{item}}</view>
</view>
.homeContainer{
padding: 20rpx;
}
.content{
width: 100%;
height: 600rpx;
line-height: 600rpx;
text-align: center;
background:#eee;
color: #1a74f1;
font-size: 64rpx;
border-radius: 10rpx;
margin-bottom: 10rpx;
}
Page({ data:{ contentList:[] }, onLoad(){ const contentList = this.getDataFromServer(); this.setData({contentList}); }, getDataFromServer(){ let result = ["肯德基宅急送","云海肴","西贝莜面村","眉州东坡","华莱士"]; return result; }, onReachBottom(){ console.log("on reach bottom"); console.log("上拉触底,获取数据追加列至列表中"); const appendData = ["其他","其他","其他","其他","其他"]; const newContentList = [...this.data.contentList,...appendData]; this.setData({contentList:newContentList}); }, onPullDownRefresh(){ console.log("on pull down refresh"); console.log("下拉刷新,获取最新列表数据"); this.getDataFromServer(); } })
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。