前言

搜了一堆,是反对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;  },

亲测,好使~

以上

参考链接

官网文档链接