当前位置:网站首页>Detailed tutorial on the use of setinterval timing function of wechat applet
Detailed tutorial on the use of setinterval timing function of wechat applet
2022-04-23 14:05:00 【one billion twenty-nine million one hundred and seventy-nine th】
1、setInterval The understanding of the
(1)setInterval understand
setInterval Timing function , Is how long to delay the non-stop call setInterval The function in , I want to know more about setInterval function , Let's take a look first setInterval Function components .
(2)setInterval form
setInterval(function () {}, Time ).function () {} Just keep executing functions , Time is how long it's delayed. Keep executing , a key function () {} function
Concrete example :
setInterval(function () {
//.toClock1() Is a concrete function , Write outside
_this.toClock1();}, 6000);
(3)setInterval Need to be closed
Use clearInterval() To close , See the following for specific use
clearInterval()
2、setInterval Put it in wechat applet onshow In the function
onShow: Triggered when this page is displayed or when you jump back to the applet from the background , Triggered when returning from the jump page , Can't pass parameters
3、setInterval Specific use
(1) Set global variables timer(timer Whatever the )
// In wechat applet data Write the following code in ,timer Global variables
data: {
timer: null,
},
(2)onshow Write setInterval function
onShow: function () {
const _this = this
// Timer The function is assigned to timer convenient clearInterval() Use
_this.data.timer = setInterval(
function () {
_this.toClock1();
}, 6000);
_this.setData({
timer:_this.data.timer
});
},
toClock1() function
// Contents of timing function execution Play by yourself Write your own code
toClock1(){
console.log(this.data.timer)
}
3、 Leave the current page and close setInterval Timing function
Code placed in onhide inside
onHide: function () {
// close clearInterval Timing function
clearInterval(this.data.timer);
this.setData({
timer: null
});
console.log(this.data.timer)
},
WeChat applet more practical skills, pay attention to the official account below.
版权声明
本文为[one billion twenty-nine million one hundred and seventy-nine th]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231401297853.html
边栏推荐
猜你喜欢
微信小程序获取登录用户信息、openid和access_token
使用Postman进行Mock测试
nodejs通过require读取本地json文件出现Unexpected token / in JSON at position
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
专题测试05·二重积分【李艳芳全程班】
scikit-learn构建模型的万能模板
Interesting talk about network protocol
STM32学习记录0007——新建工程(基于寄存器版)
微信小程序进行蓝牙初始化、搜索附近蓝牙设备及连接指定蓝牙(一)
33 million IOPs, 39 microsecond delay, carbon footprint certification, who is serious?
随机推荐
pthread_self()为何重复了
request模块
Chrome插件 之 Selenium IDE、XPath 安装
Oracle alarm log alert Chinese trace and trace files
SPC简介
快速安装mongodb
Restful WebService和gSoap WebService的本质区别
程序编译调试学习记录
记录一个奇怪的bug:缓存组件跳转之后出现组件复制
mysql新表,自增id长达20位,原因竟是......
Cdh6 based on CM management 3.2 cluster integration atlas 2 one
腾讯根据ip解析地址
对List集合进行分页
Record a strange bug: component copy after cache component jump
接口文档yaml
烟雾传感器(mq-2)使用详细教程(基于树莓派3b+实现)
Strange bug of cnpm
全局变量能否放在头文件中定义
浅谈基于openssl的多级证书,Multi-level CA的签发和管理,以及双向认证
修改ddt生成的测试用例名称