当前位置:网站首页>Various ways of writing timed tasks of small programs
Various ways of writing timed tasks of small programs
2022-04-23 05:01:00 【Chen junyang】
The first way :
(1) Calling code
var that = this;
this.sendCode()
(2) Timing task code :
// Timing task (60 Auto end in seconds )
sendCode: function (e) {
var times = 0;
var i = setInterval(function () {
times++;
if (times >= 60) {
wx.showToast({// Message box
title: ' End the scheduled task ',
icon: 'none',
duration: 2000
})
clearInterval(i);// Turn off scheduled tasks
} else {
// Business logic
}
}, 1000)
}
The second way :
(1) Calling code : Use it directly .
(2) Timing task code :
var that = this;
var times = 0;
that.setData({
selectCode: setInterval(function () {
times++;
if (times >= 60) {
clearInterval(that.data.selectCode);// Turn off scheduled tasks
} else {
// Business logic
}
}, 1000) // Timing interval Here is 1 second
})
The third way :
var timer; // timer
Page({
// ... Omit
// Custom start button
startBtn: function () {
console.log(" Start button ");
Countdown();
},
// Custom pause button
pauseBtn: function () {
console.log(" Pause button ");
clearTimeout(timer);
},
});
// count down
function Countdown() {
timer = setTimeout(function () {
console.log("----Countdown----");
Countdown();
}, 1000);
};
版权声明
本文为[Chen junyang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220552495376.html
边栏推荐
- Mac 进入mysql终端命令
- 深度学习笔记 —— 微调
- A trinomial expression that causes a null pointer
- C. Tree infection (simulation + greed)
- 用LCR表完美测试无线充电系统中的线圈
- 《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
- Mac enters MySQL terminal command
- Customize the navigation bar at the top of wechat applet (adaptive wechat capsule button, flex layout)
- 深度学习笔记 —— 数据增广
- AQS源码阅读
猜你喜欢
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
Field injection is not recommended using @ Autowired
Opencv + clion face recognition + face model training
Use model load_ state_ Attributeerror appears when dict(): 'STR' object has no attribute 'copy‘
[WinUI3]編寫一個仿Explorer文件管理器
View, modify and delete [database] table
Use the built-in function of win to transfer files between two computers in the same LAN (the speed is the same as that between local disks)
POI export message list (including pictures)
Pixel mobile phone brick rescue tutorial
Introduction to raspberry pie 3B - system installation
随机推荐
Details related to fingerprint payment
Learning Android from scratch -- baseactivity and activitycollector
Painless upgrade of pixel series
洛谷P2731骑马修栅栏
AQS源码阅读
Jetpack -- lifecycle usage and source code analysis
PHP 统计指定文件夹下文件的数量
Use the built-in function of win to transfer files between two computers in the same LAN (the speed is the same as that between local disks)
[2021] Spatio-Temporal Graph Contrastive Learning
C. Tree Infection(模拟+贪心)
【数据库】表的查看、修改和删除
SCP command details
COM in wine (2) -- basic code analysis
用LCR表完美测试无线充电系统中的线圈
Thoughts on a small program
【数据库】MySQL多表查询(一)
HRegionServer的详解
MySQL memo (for your own query)
Differences between redis and MySQL
POI export message list (including pictures)