当前位置:网站首页>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
边栏推荐
- Perfect test of coil in wireless charging system with LCR meter
- MySQL 慢查询
- QPushButton slot function is triggered multiple times
- Detailed explanation of hregionserver
- Machine learning - linear regression
- Innovation training (XI) airline ticket crawling company information
- 《2021多多阅读报告》发布,95后、00后图书消费潜力攀升
- Sword finger offer: the median in the data stream (priority queue large top heap small top heap leetcode 295)
- SCP command details
- Wechat payment function
猜你喜欢
AQS source code reading
Innovation training (IV) preliminary preparation - server
Deep learning notes - object detection and dataset + anchor box
[2021] Spatio-Temporal Graph Contrastive Learning
Excel uses the functions of replacement, sorting and filling to comprehensively sort out financial data
DIY is an excel version of subnet calculator
Wechat payment function
[2021] Spatio-Temporal Graph Contrastive Learning
AQS源码阅读
[WinUI3]編寫一個仿Explorer文件管理器
随机推荐
Wine (COM) - basic concept
Innovation training (IX) integration
JS generates a specified number of characters according to some words
QPushbutton 槽函数被多次触发
Progress of innovation training (III)
负载均衡简介
PHP 统计指定文件夹下文件的数量
Excel protects worksheets and workbooks from damage
Field injection is not recommended using @ Autowired
vscode ipynb文件没有代码高亮和代码补全解决方法
2022/4/22
[winui3] write an imitation Explorer file manager
Day. JS common methods
Arduino UNO r3+LCD1602+DHT11
[winui3] Écrivez une copie du gestionnaire de fichiers Explorer
信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
Differences between redis and MySQL
Use AES encryption - reuse the wisdom of predecessors
Introduction to raspberry pie 3B - system installation
什么是指令周期,机器周期,和时钟周期?