当前位置:网站首页>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
边栏推荐
- [database] MySQL basic operation (basic operation ~)
- CLion+OpenCV identify ID number - detect ID number
- js 判断数字字符串中是否含有字符
- [2022 ICLR] Pyramid: low complexity pyramid attention for long range spatiotemporal sequence modeling and prediction
- Innovation training (XII) reptile
- redis数据类型有哪些
- Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
- Learning Android II from scratch - activity
- Unity C e-learning (IV)
- What's the difference between error and exception
猜你喜欢

Repair of self calibration SPC failure of Tektronix oscilloscope dpo3054
![[WinUI3]编写一个仿Explorer文件管理器](/img/3e/62794f1939da7f36f7a4e9dbf0aa7a.png)
[WinUI3]编写一个仿Explorer文件管理器

深度学习笔记 —— 数据增广

Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)

Painless upgrade of pixel series

Cross border e-commerce | Facebook and instagram: which social media is more suitable for you?

Making message board with PHP + MySQL

2022/4/22

【数据库】表的查看、修改和删除

Spell it! Two A-level universities and six B-level universities have abolished master's degree programs in software engineering!
随机推荐
QPushbutton 槽函数被多次触发
Wechat payment function
信息学奥赛一本通 1955:【11NOIP普及组】瑞士轮 | OpenJudge 4.1 4363:瑞士轮 | 洛谷 P1309 [NOIP2011 普及组] 瑞士轮
leetcode——启发式搜索
Details related to fingerprint payment
Learning Android from scratch -- Introduction
Sword finger offer: the path with a certain value in the binary tree (backtracking)
[winui3] write an imitation Explorer file manager
Harmonious dormitory (linear DP / interval DP)
[2022 ICLR] Pyraformer: Low-Complexity Pyramidal Attention for Long-Range 时空序列建模和预测
#define 定义常量和宏,指针和结构体
Deep learning notes - fine tuning
redis和mysql区别
持续集成(CI)/持续交付(CD)如何彻底改变自动化测试
Graduation project
Download PDF from HowNet (I don't want to use CAJViewer anymore!!!)
The 2021 more reading report was released, and the book consumption potential of post-95 and Post-00 rose
POI export message list (including pictures)
2022/4/22
MySQL -- execution process and principle of a statement