Kaynağa Gözat

bug fix: MessageCenter unsubscribe基本功能出错

任一存 2 yıl önce
ebeveyn
işleme
4ab76badcc
2 değiştirilmiş dosya ile 9 ekleme ve 7 silme
  1. 1 1
      src/utils.js
  2. 8 6
      src/views/PanoView.vue

+ 1 - 1
src/utils.js

@@ -267,7 +267,7 @@ export class MessageCenter {
       return
     }
 
-    if (!Object.prototype.hasOwnProperty.call(this._recorder, message)) {
+    if (Object.prototype.hasOwnProperty.call(this._recorder, message)) {
       const idx = this._recorder[message].indexOf(callback)
       if (idx !== -1) {
         this._recorder[message].splice(idx, 1)

+ 8 - 6
src/views/PanoView.vue

@@ -117,13 +117,17 @@ export default {
       }
     }, 500)
     this.scene = this.$route.params.scene
-
     window.__krfn = __krfn
 
     this.loadScene()
+    this.$msgCenter.subscribe('clickHotspot', this.onClickHotspot)
 
-    this.$msgCenter.subscribe('clickHotspot', (hotspotName) => {
-      console.log('hotspotName: ', hotspotName)
+  },
+  beforeDestroy() {
+    this.$msgCenter.unsubscribe('clickHotspot', this.onClickHotspot)
+  },
+  methods: {
+    onClickHotspot(hotspotName) {
       let someData = this.scene.someData
       if (typeof someData == "string") {
         someData = JSON.parse(this.activeItem.someData)
@@ -138,9 +142,7 @@ export default {
           // this.$router.replace({ name: 'PanoView', params: { scene: clickedHotspot.secne } })
         }
       }
-    })
-  },
-  methods: {
+    },
     loadScene() {
       $("#pano").empty()
       window.vrInitFn = () => {