uniapp之 onShow、onPullDownRefresh 等不生效 使用 mounted 设置定时器

前言

因项目的需求,我需要 在某个页面 设置定时器,

我这个定时器之所以使用 vue生命周期中的 mounted 以及  beforeDestroy 是因为 此页面是个 子组件 暂不支持 小程序中的 onShow、 onUnload 以及 onHide 页面生命周期

因此代码如下

别忘了在  data 里面要定义     timer : null

  mounted() {
      this.getConnector()
      if (this.timer) {
        clearInterval(this.timer)
      } else {
        this.timer = setInterval(() => {
          setTimeout(() => {
            this.getConnector()
          }, 0)
          console.log('刷新', +new Date());
        }, 1000 * 60)
      }
      console.log(this.connectorList, this.connectorCode);
    },
 beforeDestroy() {
      clearInterval(this.timer)
      this.timer = null
    }

后续

因老大提出让我 设置下拉刷新 ,此定时器就作废,写篇文章记录下

提示

onPullDownRefresh 属于页面生命周期函数

 因此下拉刷新事件 在子组件里面使用不了,后我把这个函数写在父组件里就可以了,

猜你喜欢

转载自blog.csdn.net/LJM51200/article/details/128497318