当前位置:网站首页>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
边栏推荐
- Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
- 如何写出高质量的代码?
- Zblogphp breadcrumb navigation code
- Error: module not found: error: can't resolve 'xxx' in 'XXXX‘
- 把欧拉的创新带向世界 SUSE 要做那个引路人
- Tianlong Babu TLBB series - single skill group injury
- 《剑来》语句摘录(七)
- Singleton mode encapsulates activity management class
- 学习笔记5--高精地图解决方案
- 《微信小程序-基础篇》小程序中的事件与冒泡
猜你喜欢
AtCoder Beginner Contest 258「ABCDEFG」
Swift tableview style (I) system basic
苹果 5G 芯片研发失败?想要摆脱高通为时过早
Universal double button or single button pop-up
ConstraintLayout官方提供圆角ImageFilterView
@SerializedName注解使用
Learning note 4 -- Key Technologies of high-precision map (Part 2)
Learning notes 5 - high precision map solution
A high density 256 channel electrode cap for dry EEG
【 conseils 】 obtenir les valeurs des axes X et y de la fonction cdfplot dans MATLAB
随机推荐
How to plan the career of a programmer?
请问大佬们 有遇到过flink cdc mongdb 执行flinksql 遇到这样的问题的么?
"Everyday Mathematics" serial 58: February 27
【观察】跨境电商“独立站”模式崛起,如何抓住下一个红利爆发时代?
MySQL character type learning notes
Click the picture in the mobile browser and the picture will not pop up
如何判断线程池已经执行完所有任务了?
[论文阅读] KGAT: Knowledge Graph Attention Network for Recommendation
Interview: how does the list duplicate according to the attributes of the object?
A high density 256 channel electrode cap for dry EEG
Uni app running to wechat development tool cannot Preview
How do programmers live as they like?
RMS TO EAP通过MQTT简单实现
> Could not create task ‘:app:MyTest. main()‘. > SourceSet with name ‘main‘ not found. Problem repair
AtCoder Beginner Contest 258「ABCDEFG」
Pagoda panel MySQL cannot be started
MySQL digital type learning notes
Usage differences between isempty and isblank
Apple 5g chip research and development failure? It's too early to get rid of Qualcomm
A large number of virtual anchors in station B were collectively forced to refund: revenue evaporated, but they still owe station B; Jobs was posthumously awarded the U.S. presidential medal of freedo