Created
November 8, 2019 15:12
-
-
Save DJanoskova/cb8e822bafcc4de5ca06338206210b3a 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="handleOutsideClick"> | |
| <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, | |
| closeOnClick: true | |
| } | |
| }, | |
| created () { | |
| ModalBus.$on('open', ({ component, title = '', props = null, closeOnClick = true }) => { | |
| this.component = component | |
| this.title = title | |
| this.props = props | |
| this.closeOnClick = closeOnClick | |
| }) | |
| document.addEventListener('keyup', this.handleKeyup) | |
| }, | |
| beforeDestroy () { | |
| document.removeEventListener('keyup', this.handleKeyup) | |
| }, | |
| methods: { | |
| handleOutsideClick () { | |
| if (!this.closeOnClick) return | |
| this.handleClose() | |
| }, | |
| 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