瀏覽代碼

Merge branch 'master' of http://git.ycjcjy.com/honghe/roundabout

[baozhangchao] 3 年之前
父節點
當前提交
f1052f6b04
共有 2 個檔案被更改,包括 15 行新增5 行删除
  1. 3
    3
      src/pages/game/game.js
  2. 12
    2
      src/pages/game/index.vue

+ 3
- 3
src/pages/game/game.js 查看文件

81
   const mntMap = {}
81
   const mntMap = {}
82
 
82
 
83
   // 初始化
83
   // 初始化
84
-  const two = new Two({
84
+  let two = new Two({
85
     fullscreen: true,
85
     fullscreen: true,
86
     autostart: true
86
     autostart: true
87
   }).appendTo(el);
87
   }).appendTo(el);
362
     stop: () => {
362
     stop: () => {
363
       isFinished = true;
363
       isFinished = true;
364
     },
364
     },
365
-    destroy: () => {
366
-    
365
+    destroy: () => {    
367
       two.unbind('update');
366
       two.unbind('update');
368
       two.pause();
367
       two.pause();
369
       el.removeChild(two.renderer.domElement);
368
       el.removeChild(two.renderer.domElement);
369
+      two = null;
370
     }
370
     }
371
   }
371
   }
372
 }
372
 }

+ 12
- 2
src/pages/game/index.vue 查看文件

5
 
5
 
6
 <script setup>
6
 <script setup>
7
   import { onBeforeUnmount, onMounted, ref } from 'vue';
7
   import { onBeforeUnmount, onMounted, ref } from 'vue';
8
-import { useRouter } from 'vue-router';
8
+import { useRouter, onBeforeRouteUpdate, onBeforeRouteLeave } from 'vue-router';
9
   import FireWorkListVue from '@/components/FireWorkList.vue';
9
   import FireWorkListVue from '@/components/FireWorkList.vue';
10
   import game from "./game.js";
10
   import game from "./game.js";
11
 
11
 
44
     })
44
     })
45
   }
45
   }
46
 
46
 
47
+  onBeforeRouteUpdate(() => {
48
+    console.log('--------ref----<', el)
49
+  })
50
+
51
+  onBeforeRouteLeave(() => {
52
+    console.log('--------onBeforeRouteLeave----<')
53
+  })
54
+
47
   onMounted(() => {
55
   onMounted(() => {
48
     gameInit()
56
     gameInit()
57
+    console.log('--------onMounted----<', el)
49
   })
58
   })
50
 
59
 
51
   onBeforeUnmount(() => {
60
   onBeforeUnmount(() => {
61
+    console.log('--------onBeforeUnmount----<', el)
52
     if (destroyRef.value) {
62
     if (destroyRef.value) {
53
-      destroyRef.value();
63
+      destroyRef.value.destroy();
54
     }
64
     }
55
   })
65
   })
56
 
66