Browse Source

事件销毁

Caner 2 years ago
parent
commit
d346fcdd12
2 changed files with 13 additions and 1 deletions
  1. 7 0
      src/components/map/map.service.ts
  2. 6 1
      src/components/map/map.vue

+ 7 - 0
src/components/map/map.service.ts

@@ -175,4 +175,11 @@ export default class MapService extends Service {
       }
     }
   }
+
+  public destory() {
+    if (Object.keys(this.marks).length) this.marks = {}
+    if (this.Maps) this.Maps.destory()
+    this.Maps = null
+    this.AMaps = null
+  }
 }

+ 6 - 1
src/components/map/map.vue

@@ -36,7 +36,9 @@
 </template>
 
 <script setup lang='ts'>
-import { onMounted, ref, watch } from 'vue'
+import {
+  onMounted, onUnmounted, ref, watch
+} from 'vue'
 import useStore from '@/pages/store/index'
 import MapService from './map.service'
 
@@ -90,6 +92,8 @@ watch(() => store.socektData, (v) => {
         const es = el.inboundAndOutboundStations[j]
         if (marks[props.Item.key][1][es.vehicleId]) {
           // 更新位置
+          console.log(123, marks[props.Item.key][1][es.vehicleId])
+
           marks[props.Item.key][1][es.vehicleId].markMap.setPosition([ es.lng, es.lat ])
           marks[props.Item.key][1][es.vehicleId].markMap.show()
         } else {
@@ -119,6 +123,7 @@ watch(() => props.Item.key, (v) => {
     }
   }
 })
+onUnmounted(() => mapService.destory())
 </script>
 
 <style lang="scss" scoped>