前言
搜了一堆,是支持Vue2 的this.$once,试了有报错,发现Vue3 被移除了,伤心,记录下解决方案。
1、data 中声明
data () {
return {
timer: null,
}
},
2、mounted 钩子中定义方案及处理函数
mounted () {
this.timer = setInterval(()=>{
//处理部分
},3000)
},
3、beforeUnmount或unmounted的钩子中销毁
beforeUnmount() {
clearInterval(this.timer)
this.timer = null;
},
亲测,好使~
以上
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。