当前位置:网站首页>Wechat applet (anti shake, throttling), which solves the problem that users keep pulling down refresh requests or clicking buttons to submit information; Get the list information and refresh the data
Wechat applet (anti shake, throttling), which solves the problem that users keep pulling down refresh requests or clicking buttons to submit information; Get the list information and refresh the data
2022-07-25 22:13:00 【Grace God】
The following code is implemented :
// Declare a variable to clear the timer
var times='',
Initialization data , I got to traverse the page
data: {
arr: [],
ye: 1,
tiao: 10
},
// Page refresh to get information
onLoad(options) {
this.getlist()
},
// Drop down to refresh data , Back before 10 Data
onPullDownRefresh() {
clearInterval(times) // Clear timer , Solve the drop-down problem , Shake proof !
times = setInterval(() => {
this.setData({
tiao: 10
})
this.getlist()
}, 2000)
},
// To obtain a list of
getlist() {
var obj = {
page: this.data.ye,
pagelimit: this.data.tiao,
}
$api.getxiala(obj).then(res => {
this.setData({
arr: res.data.data.data,
})
})
},
// Pull up to refresh the list data , Each update 10 strip , The handler of the bottom pull event on the page of the applet !
onReachBottom() {
if (this.data.tiao >= 24) { // If it has been pulled to the bottom , You can prompt a message
this.setData({
arr: [{
id: " Roll came ",
title: " It's finished ",
dec: " Drop down to refresh data ",
num: " roll "
}]
})
} else {
this.setData({
tiao: this.data.tiao + 10
})
this.getlist()
}
},
js Anti shake throttling logic ( The logic is the same )
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="demo">
<button onclick="add()"> Click refresh </button>
</div>
</body>
</html>
<script>
// Anti shake throttling logic
var time=''
function fn() {
console.log(123);
}
// Only perform once within the specified time
function add() {
clearInterval(time)
time= setInterval(() => {
this.fn()
}, 1000)
}
</script>边栏推荐
- 完啦,上班三个月,变秃了
- QML module not found
- 【C语法】void*浅说
- Why is the integer type 128 to byte -128
- Synchronized and volatile
- Dovecot set mailbox quota
- The second short contact of gamecloud 1608
- Which is reliable between qiniu business school and WeiMiao business school? Is it safe to open an account recommended by the teacher?
- El expression improves JSP
- C language: random generated number + selective sorting
猜你喜欢

磁盘空间的三种分配方式

MySQL --- 子查询 - 列子查询(多行子查询)

Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin

6-18漏洞利用-后门连接

字节跳动技术面都过了,结果还是被刷了,问HR原因竟是。。。

Get together for ten years, tell your story, millions of gifts are waiting for you

On the difference between break and continue statements

Jenkins+svn configuration

Animation curves are used every day. Can you make one by yourself? After reading this article, you will!

6-17 vulnerability exploitation - deserialization remote command execution vulnerability
随机推荐
JSP novice
C语言:随机生成数+冒泡排序
Mouseevent event -- mouse coordinate description -- Focus event -- input event -- throttle -- mousewheel (wheel event)
How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
Call of addition, subtraction, multiplication and division of integer type only
Jenkins+svn configuration
在腾讯干软件测试3年,7月无情被辞,想给划水的兄弟提个醒...
什么是类加载?类加载的过程?
ZigBee development board (nxpzigbee Development)
How to implement an app application to limit users' time use?
『SignalR』. Net using signalr for real-time communication
Ansible+cronab batch deployment patrol
jenkins+SVN配置
Wet- a good choice for people with English difficulties - console translation
What is redis? Briefly describe its advantages and disadvantages
Visitor mode
QML module not found
D3.js 学习
Unity performance optimization direction
JS timer and swiper plug-in