+
86
-

回答

可以在组件中增加一下方法来实现组件销毁前停止定时器:示例代码如下:

beforeDestroy() {
      // 组件销毁前停止定时器
       console.log("销毁");
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
},

网友回复

我知道答案,我要回答