timer-miniprogram
Xiao Cheng Xu Ding Shi Qi Guan Li Ku ,Geng He Li Di Shi Yong setTimeout He setInterval,Zai Ye Mian Xian Shi Shi Zhong Qi Ding Shi Qi ,Ye Mian Yin Cang Shi Zan Ting Ding Shi Qi ,Ye Mian Xie Zai Shi Qing Chu Ding Shi Qi . Xie Zhe Ge Ku De Yuan You Xiang Kan .
Shi Yong
Ke Can Kao example Mu Lu Xia De Shi Li Xiang Mu Huo Can Zhao Yi Xia Liu Cheng :
- Tong Guo npm An Zhuang
An Zhuang Wan Cheng Zhi Hou Zai Wei Xin Kai Fa Zhe Gong Ju Zhong Dian Ji Gou Jian npm.
- Dao Ru Xiao Cheng Xu Gua Pei Ban Ben De timer-miniprogram
// Zai Ye Mian Zhong Shi Yong
Page({
behaviors: [TimerBehavior],
onReady() {
const timer1 = this.$setTimeout(() => {
console.log('setTimeout')
})
this.$clearTimeout(timer1)
const timer2 = this.$setInterval(() => {
console.log('setInterval')
})
this.$clearInterval(timer2)
}
})
// Zai Zu Jian Zhong Shi Yong
Components({
behaviors: [TimerBehavior],
ready() {
const timer1 = this.$setTimeout(() => {
console.log('setTimeout')
})
this.$clearTimeout(timer1)
const timer2 = this.$setInterval(() => {
console.log('setInterval')
})
this.$clearInterval(timer2)
}
})
eslint Pei Zhi
Wei Liao Rang Tuan Dui Geng Hao Di Zun Shou Ding Shi Qi Shi Gui Fan ,Ni Huan Ke Yi Pei Zhi eslint Zeng Jia Dai Ma Ti Shi ,Pei Zhi Ru Xia :
// .eslintrc.js
module.exports = {
'rules': {
'no-restricted-globals': ['error', {
'name': 'setTimeout',
'message': 'Please use TimerBehavior and this.$setTimeout instead. see the link: https://github.com/o2team/timer-miniprogram'
}, {
'name': 'setInterval',
'message': 'Please use TimerBehavior and this.$setInterval instead. see the link: https://github.com/o2team/timer-miniprogram'
}, {
'name': 'clearInterval',
'message': 'Please use TimerBehavior and this.$clearInterval instead. see the link: https://github.com/o2team/timer-miniprogram'
}, {
'name': 'clearTimout',
'message': 'Please use TimerBehavior and this.$clearTimout instead. see the link: https://github.com/o2team/timer-miniprogram'
}]
}
}