vue中使用setTimeout代替setInterval进行轮询,每隔40s请求一次

1,129 阅读1分钟
refreshData() {
    const fnc = ()=> {
        this.timer = setTimeout(async ()=> {
            await Promise.all([this.getTaskStatus(), this.getTableDatas()]);
            fnc();
        }, 4e4);
    };
    this.$on('hook:beforeDestroy', ()=> {
        clearTimeout(this.timer);
        this.timer = null;
    });
    fnc();
},