Skip to content

Commit

Permalink
shop组件销毁时,销毁message 事件监听
Browse files Browse the repository at this point in the history
  • Loading branch information
arnan-wei committed Mar 2, 2020
1 parent ef5f7f1 commit 00f5494
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/components/widget/Shop.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
return {}
},
created () {
this.onMessage()
window.addEventListener('message', this.onMessage, false)
},
beforeDestroy () {
window.removeEventListener('message', this.onMessage)
},
computed: {
shopUrl () {
Expand Down Expand Up @@ -58,19 +61,17 @@
return o
}, {})
},
onMessage () {
window.addEventListener('message', (event = {}) => {
const {data} = event
const {action, payload} = data || {}
switch (action) {
case 'component.import':
this.resourcesImport(payload)
break
case 'shop.loaded':
this.onShopLoaded()
break
}
}, false)
onMessage (event = {}) {
const {data} = event
const {action, payload} = data || {}
switch (action) {
case 'component.import':
this.resourcesImport(payload)
break
case 'shop.loaded':
this.onShopLoaded()
break
}
},
resourcesImport (payload) {
Server({
Expand Down

0 comments on commit 00f5494

Please sign in to comment.