Skip to content

Instantly share code, notes, and snippets.

@phillip-haydon
Last active April 26, 2017 05:59
Show Gist options
  • Save phillip-haydon/2a7029df9789b9838f3948daeb551023 to your computer and use it in GitHub Desktop.
Save phillip-haydon/2a7029df9789b9838f3948daeb551023 to your computer and use it in GitHub Desktop.
custom modal component vue
<template>
<div id="modal" v-bind:class="{ 'show': show }">
<div class="modal-dialog">
<div class="modal-content">
<div></div>
</div>
</div>
<button v-on:click="$bus.$emit('hide-tm')">Close</button>
</div>
</template>
<script>
export default {
name: 'custom-modal',
data() {
return {
show: false,
currentComponent: null,
blankDiv: global.window.document.createElement('DIV')
}
},
created() {
this.$bus.$on('show-tm', (componentName, data = {}) => {
this.show = true
let Component = this.$options.components[componentName]
this.currentComponent = new Component({
el: this.$el.querySelector('div.modal-content > div'),
parent: this,
data: data
})
})
this.$bus.$on('hide-tm', () => {
this.show = false
this.currentComponent = {}
this.$el.replaceChild(this.blankDiv, this.$el.querySelector('div.modal-content > div'))
})
},
components: []
}
</script>
<style lang="scss">
div#modal {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.3);
opacity: 0;
visibility: hidden;
transition: opacity 200ms ease-in;
&.show {
opacity: 1;
visibility: visible;
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment