Skip to content

Instantly share code, notes, and snippets.

@DJanoskova
Created November 8, 2019 12:07
Show Gist options
  • Select an option

  • Save DJanoskova/ec998e6842cb7a3b4f954f36b43e32c0 to your computer and use it in GitHub Desktop.

Select an option

Save DJanoskova/ec998e6842cb7a3b4f954f36b43e32c0 to your computer and use it in GitHub Desktop.
<template>
<Modal :isOpen="!!component" :title="title" @onClose="handleClose">
<component :is="component" @onClose="handleClose" v-bind="props" />
</Modal>
</template>
<script>
import { ModalBus } from '../eventBus'
import Modal from './common/Modal'
export default {
data () {
return {
component: null,
title: '',
props: null
}
},
created () {
ModalBus.$on('open', ({ component, title = '', props = null }) => {
this.component = component
this.title = title
this.props = props
})
document.addEventListener('keyup', this.handleKeyup)
},
beforeDestroy () {
document.removeEventListener('keyup', this.handleKeyup)
},
methods: {
handleClose () {
this.component = null
},
handleKeyup (e) {
if (e.keyCode === 27) this.handleClose()
}
},
components: { Modal },
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment