浏览代码

fix: 弹幕组件定时器清除的生命周期 (#585)

* fix: 折叠面板适配小程序

* docs: 折叠面板文档修改

* fix: 折叠面板H5环境适配

* feat: 弹幕组件

* fix: 适配小程序

* feat: countUp组件开发适配

* fix: 弹幕组件销毁清空定时器

* fix: 增加onDeactivated声明周期
Ymm0008 4 年之前
父节点
当前提交
7dacd8aec7
共有 2 个文件被更改,包括 25 次插入1 次删除
  1. 13 1
      src/packages/__VUE/barrage/index.taro.vue
  2. 12 0
      src/packages/__VUE/barrage/index.vue

+ 13 - 1
src/packages/__VUE/barrage/index.taro.vue

@@ -14,7 +14,9 @@ import {
   reactive,
   toRefs,
   watch,
-  nextTick
+  nextTick,
+  onUnmounted,
+  onDeactivated
 } from 'vue';
 import Taro from '@tarojs/taro';
 import { createComponent } from '../../utils/create';
@@ -68,6 +70,16 @@ export default create({
       run();
     });
 
+    onUnmounted(() => {
+      clearInterval(timer);
+      timer = 0;
+    });
+
+    onDeactivated(() => {
+      clearInterval(timer);
+      timer = 0;
+    });
+
     watch(
       () => props.danmu,
       (newValue, oldVlaue) => {

+ 12 - 0
src/packages/__VUE/barrage/index.vue

@@ -10,6 +10,8 @@
 import {
   computed,
   onMounted,
+  onUnmounted,
+  onDeactivated,
   ref,
   reactive,
   toRefs,
@@ -72,6 +74,16 @@ export default create({
       run();
     });
 
+    onUnmounted(() => {
+      clearInterval(timer);
+      timer = 0;
+    });
+
+    onDeactivated(() => {
+      clearInterval(timer);
+      timer = 0;
+    });
+
     watch(
       () => props.danmu,
       (newValue, oldVlaue) => {