开发者社区 问答 正文

vue组件里的定时器要怎么销毁?

vue组件里的定时器要怎么销毁?

展开
收起
游客7iokfgo4yexey 2020-05-23 12:00:13 1594 分享 版权
1 条回答
写回答
取消 提交回答
  • 可以在beforeDestroy里写清除函数 const timer = setInterval(() =>{ // 某些定时器操作 }, 500); // 通过$once来监听定时器,在beforeDestroy钩子可以被清除。 this.$once('hook:beforeDestroy', () => { clearInterval(timer); }) 问题来源于GitHub,查看更多答案,请查看https://github.com/haizlin/fe-interview/issues/446

    2020-05-23 12:53:55
    赞同 展开评论