vue 定时器创建和销毁
由于单页面应用路由地址变更页面不会刷新,定时器一直会存在,页面组件销毁时要清除const timer = setTimeout(() => {this.fn()}, 3000);this.$once('hook:beforeDestroy', () => {clearInterval(timer );})//或this.time...
·
由于单页面应用路由地址变更页面不会刷新,定时器一直会存在,页面组件销毁时要清除
const timer = setTimeout(() => {
this.fn()
}, 3000);
this.$once('hook:beforeDestroy', () => {
clearInterval(timer );
})
//或
this.timer = setTimeout(() => {
this.fn()
}, 3000);
destroyed(){
clearInterval(this.timer );
}
更多推荐
已为社区贡献3条内容
所有评论(0)