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

  • vue 项目中,定时器(setInterval)的写法:
    fetchJobList是一个方法,里面有dispatch一个action进行请求接口的代码。
    data () {
        return {
            intervalId: 0
        }
    },
    created () {
        this.fetchJobList()
        this.intervalId = setInterval(() => {
            this.fetchJobList()
        }, 5000)
    },
    beforeDestroy () {
        clearInterval(this.intervalId)
    }
原文地址:https://www.cnblogs.com/cag2050/p/8335899.html