vue 项目中,定时器(setInterval)的写法

  • vue 项目中,定时器(setInterval)的写法:
    fetchJobList是一个方法,里面有dispatch一个action进行请求接口的代码。
    data () {
        return {
            intervalId: 0
        }
    },
    created () {
        this.fetchJobList()
        this.intervalId = setInterval(() => {
            this.fetchJobList()
        }, 5000)
    },
    beforeDestroy () {
        clearInterval(this.intervalId)
    }

posted on 2018-01-23 15:07  cag2050  阅读(9199)  评论(0编辑  收藏  举报

导航