微信小程序 组件里面定时器无法清除?
发布于 5 年前 作者 xiulancai 4026 次浏览 来自 官方Issues

在定时器里面设置定时器,但是在组件的生命周期里面 清除不了定时器

pageLifetimes: {
  show: function () {
    // 页面被展示
  },
  hide: function () {
    clearInterval(this.data.timer)
    innerAudioContext.stop();
    innerAudioContext.destroy()
  },
  resize: function (size) {
    // 页面尺寸变化
  }
},
ready(){
  // this.Initialization()
},
lifetimes: {
  attached: function () {
    innerAudioContext.onPlay(function(){
      console.log('开始播放')
    })
    innerAudioContext.onError(function (errCode){
      console.log('播放错误:' + errCode)
    })
  },
  detached: function () {
    clearInterval(this.data.timer)
    innerAudioContext.stop();
    // this.getrecord()
    // 在组件实例被从页面节点树移除时执行
  },
},
1 回复

麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部