微信小程序定时器

  

// 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