微信小程序定时器

时间:2021-01-15 13:25:18   收藏:0   阅读:157

  

// pages/audit/audit.js
Page({
  数据
  data: {
    time: 3,
    timer: null
  },

  onLoad: function (options) {},
   onShow() { let _this
= this; this.setData({ timer: setInterval(() => { _this.setTimeCount() }, 1000) }) },
  定时器 setTimeCount: function () { let time
= this.data.time time--; if (time <= 0) { wx.redirectTo({ url: /pages/index/index }) return false; } this.setData({ time: time, }) },
  销毁定时器 onUnload: function () { clearInterval(
this.data.timer); }, gopage() { wx.redirectTo({ url: /pages/index/index }) } })

clearInterval(number intervalID)

取消由 setInterval 设置的定时器。

原文:https://www.cnblogs.com/yugueilou/p/14280514.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!