当前位置:网站首页>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>边栏推荐
- Having met a tester with three years' experience in Tencent, I saw the real test ceiling
- 2年功能测试,却感觉自己什么都不会,2022我该何去何从?
- Usage of in in SQL DQL query
- C language left value and right value description [easy to understand]
- How to resolve a domain name to multiple IP addresses?
- After three years of software testing at Tencent, I was ruthlessly dismissed in July, trying to wake up my brother who was paddling
- internship:普通常用的工具类编写
- 启牛商学院和微淼商学院哪个靠谱?老师推荐的开户安全吗?
- Open source RSS subscriber freshrss
- Don't know mock test yet? An article to familiarize you with mock
猜你喜欢

How to resolve a domain name to multiple IP addresses?

Selenium basic use and use selenium to capture the recruitment information of a website (continuously updating)

核电站在席卷欧洲的热浪中努力保持安全工作

TFrecord写入与读取

聚名十年,说出你的故事,百万豪礼等你拿

编译和反编译

Wechat applet application development competition works comprehensive development record - Jinlu cultural tourism (cloud development - Overview)

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

What should I do if I encounter the problem of verification code during automatic testing?

Guiding principles of information security construction
随机推荐
H5幸运刮刮乐抽奖 免公众号+直运营
编译和反编译
[fan Tan] those stories that seem to be thinking of the company but are actually very selfish (I: building wheels)
How to call the size of two numbers with a function--- Xiao Tang
Ansible+cronab batch deployment patrol
Title: give a group of arrays, arranged from large to small and from small to large.
虚拟内存与磁盘
JSP初识
On the difference between break and continue statements
JS timer and swiper plug-in
QML module not found
访问者模式(visitor)模式
D3.js learning
这次龙蜥展区玩的新花样,看看是谁的 DNA 动了?
All you want to know about interface testing is here
Internship: writing common tool classes
How to solve the problem of using the download Plug-in for export?
What should I do if I encounter the problem of verification code during automatic testing?
win10搭建flutter环境踩坑日记
MySQL - subquery - column subquery (multi row subquery)