当前位置:网站首页>Implementation of wechat applet bottom loading and pull-down refresh
Implementation of wechat applet bottom loading and pull-down refresh
2022-07-05 10:24:00 【InfoQ】
Bottom touch loading
- Encapsulates a loader function
- This is triggered when the listening page is loaded loader function
- Trigger this function again when the bottom is detected
onLoad: function (options) {
this.loadBooks(this.data.books.length)
},
onReachBottom: function () {
this.loadBooks(this.data.books.length)
},
loadBooks: function () {
},
onload
onReachBottom
loader Functional thinking
skip(n)
loader Function implementation
- call wx Developed by the cloud api,
skip(n)
From the... Of the set n Item start getlimit(n)
At most n Elements .
- adopt get Obtain corresponding data , Here for n After 6 Data .
- adopt
cancat()
To realize the merging of arrays, we need to pay attention to the followinglimit(n)
Direct use has 20 The length limit of , If there is a need , Need to get 20 More than one data set , Then we can solve it in the cloud function .
loadBooks: function (n) {
wx.cloud.database().collection('books').skip(n).limit(6).get().then(res => {
console.log(res.data)
this.setData({
books: this.data.books.concat(res.data)
})
})
},
Touch the bottom to load the animation
<view class="loader" wx:if="{{isLoader}}">
<view class="dot"></view>
<view class="dot"></view>
<view class="dot"></view>
<view class="dot"></view>
<view class="dot"></view>
</view>
.dot {
width: 24rpx;
height: 24rpx;
background: #3ac;
border-radius: 100%;
display: inline-block;
animation: slide 1s infinite;
}
.dot:nth-child(n) {
animation-delay: 0.1s;
background: #6cd793;
}
@keyframes slide {
0% {
transform: scale(1);
}
50% {
opacity: .3;
transform: scale(2);
}
100% {
transform: scale(1);
}
}
Advantages of bottom loading
The drop-down refresh
- At the same level of the corresponding page json Configure it in the file
enablePullDownRefresh
Make ittrue
, Here is the drop-down refresh setting of the corresponding page
{
"usingComponents": {},
"enablePullDownRefresh": true,
}
- Use
onPullDownRefresh
Monitor user pull-down action
onPullDownRefresh: function () {},
- call wx Loading api
onPullDownRefresh: function () {
console.log(1)
// Show load... In the title bar
wx.showNavigationBarLoading()
wx.showLoading({
title: ' Refreshing ...',
})
wx.cloud.database().collection('books').skip(0).limit(6).get().then(res => {
this.setData({
books: res.data
})
wx.hideLoading();
// Hide navigation bar loading animation
wx.hideNavigationBarLoading();
// Stop the drop-down refresh
wx.stopPullDownRefresh();
})
},
wx.showNavigationBarLoading()
Display and load animation in the navigation bar
wx.hideNavigationBarLoading()
Hide navigation bar loading animation
wx.stopPullDownRefresh()
Stop the drop-down refresh
Last
边栏推荐
- ArcGIS Pro creating features
- [论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
- Window下线程与线程同步总结
- Who is the "conscience" domestic brand?
- What is the most suitable book for programmers to engage in open source?
- 学习笔记4--高精度地图关键技术(下)
- 请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
- Glide advanced level
- ConstraintLayout官方提供圆角ImageFilterView
- SAP UI5 ObjectPageLayout 控件使用方法分享
猜你喜欢
RMS TO EAP通过MQTT简单实现
ArcGIS Pro creating features
Energy momentum: how to achieve carbon neutralization in the power industry?
AtCoder Beginner Contest 258「ABCDEFG」
ConstraintLayout的流式布局Flow
伪类元素--before和after
WorkManager學習一
Solution of ellipsis when pytorch outputs tensor (output tensor completely)
IDEA新建sprintboot项目
mongoDB副本集
随机推荐
Pseudo class elements -- before and after
Have you learned to make money in Dingding, enterprise micro and Feishu?
Have the bosses ever encountered such problems in the implementation of flinksql by Flink CDC mongdb?
Customize the left sliding button in the line in the applet, which is similar to the QQ and Wx message interface
【JS】数组降维
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
"Everyday Mathematics" serial 58: February 27
橫向滾動的RecycleView一屏顯示五個半,低於五個平均分布
程序员如何活成自己喜欢的模样?
Swift uses userdefaults and codable to save an array of class objects or structure instances
请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
What is the most suitable book for programmers to engage in open source?
Universal double button or single button pop-up
学习笔记6--卫星定位技术(上)
WorkManager的学习二
[system design] index monitoring and alarm system
Pagoda panel MySQL cannot be started
Today in history: the first e-book came out; The inventor of magnetic stripe card was born; The pioneer of handheld computer was born
MySQL digital type learning notes
自动化规范检查软件如何发展而来?