@vue定时器和关闭定时器
vue定时器和关闭定时器
mounted() {//页面加载完成后执行方法(启动定时器) clearInterval(this.timer) this.setTimer() }, //distroyed: function () {//页面关闭后关闭定时器(并没用) // console.log('distroyed') // clearInterval(this.timer) //}, beforeDestroy() {//页面关闭前关闭定时器 (这个才有用) clearInterval(this.timer) }, methods: { setTimer: function () { this.timer = setInterval( () => { console.log("定时执行方法"); }, 3000); }, }
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/214236.html原文链接:https://javaforall.net
