前言
搜了一堆,是支持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;
},
亲测,好使~
以上