main.js 实现 用settimeout 实现setinterval window.$bus = new Vue() window.setTimeToInterval = function (delay) { if (window.intervalTimeout) { clearTimeout(window.intervalTimeout) window.intervalTimeout = null } window.intervalTimeout = setTimeout(() => { log('定时请求时间为:' + delay) this.$bus.$emit('setIntervalGet') this.setTimeToInterval(delay) }, delay) }
页面调用 mounted 的时候 加监听 window.$bus.$on('setIntervalGet', function () { // do something }) destroyed 销毁监听 window.$bus.$off('setIntervalGet') // 方法调用 window.setTimeToInterval(10)
标签:vue,setinterval,bus,setTimeToInterval,delay,window,intervalTimeout,setIntervalGe From: https://www.cnblogs.com/loveMis/p/17144013.html