JS 定时器-setInterval、clearInterval、setTimeout

在微信小程序里写的:

// pages/splash/splash.js
const app = getApp()
Page({
  data: {
    remainSecond: 3

  },
  // 页面渲染完成后 调用
  onReady: function() {
    let that = this
    let interval = setInterval(function() {
      let rs = that.data.remainSecond
      rs--
      if (rs < 0) {
        clearInterval(interval);
      }
      this.setData({
        remainSecond: rs
      })
    }.bind(this), 1000)
    setTimeout(function() {
      wx.reLaunch({
        url: '../write/write',
      })
    }, 3000)

  }
})

猜你喜欢

转载自www.cnblogs.com/pu369/p/11411890.html