Created
November 8, 2019 12:07
-
-
Save DJanoskova/ec998e6842cb7a3b4f954f36b43e32c0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <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