当前位置:网站首页>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
边栏推荐
- 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
- 官网给的这个依赖是不是应该为flink-sql-connector-mysql-cdc啊,加了依赖调
- Uni app running to wechat development tool cannot Preview
- A high density 256 channel electrode cap for dry EEG
- Using directive in angualr2 to realize that the picture size changes with the window size
- Redis如何实现多可用区?
- 学习笔记4--高精度地图关键技术(下)
- 如何判断线程池已经执行完所有任务了?
- Matrix processing practice
- @Jsonadapter annotation usage
猜你喜欢
Atcoder beginer contest 254 "e BFS" f st table maintenance differential array GCD "
学习笔记4--高精度地图关键技术(下)
[论文阅读] CKAN: Collaborative Knowledge-aware Atentive Network for Recommender Systems
[C language] the use of dynamic memory development "malloc"
ArcGIS Pro creating features
Pagoda panel MySQL cannot be started
《微信小程序-基础篇》小程序中的事件与冒泡
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
WorkManager的学习二
如何写出高质量的代码?
随机推荐
How to write high-quality code?
php解决redis的缓存雪崩,缓存穿透,缓存击穿的问题
pytorch输出tensor张量时有省略号的解决方案(将tensor完整输出)
Lepton 无损压缩原理及性能分析
一个程序员的职业生涯到底该怎么规划?
Singleton mode encapsulates activity management class
Swift saves an array of class objects with userdefaults and nssecurecoding
到底谁才是“良心”国产品牌?
Design and Simulation of fuzzy PID control system for liquid level of double tank (matlab/simulink)
Interview: how does the list duplicate according to the attributes of the object?
请问postgresql cdc 怎么设置单独的增量模式呀,debezium.snapshot.mo
How to plan the career of a programmer?
Implementation of smart home project
驱动制造业产业升级新思路的领域知识网络,什么来头?
【JS】数组降维
程序员如何活成自己喜欢的模样?
[JS] array dimensionality reduction
Unity particle special effects series - the poison spray preform is ready, and the unitypackage package is directly used - on
Workmanager Learning one
How can PostgreSQL CDC set a separate incremental mode, debezium snapshot. mo