Created
November 8, 2017 16:49
-
-
Save blocka/362721a9ebb60c66669efacd27852628 to your computer and use it in GitHub Desktop.
Example modal
This file contains 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> | |
<div> | |
<div class="modal-mask" v-if="show" @click="requestClose && requestClose()"> | |
<div class="modal-wrapper"> | |
<div class="modal-container" @click.stop :style="{width: width + 'px'}"> | |
<slot></slot> | |
</div> | |
</div> | |
</div> | |
</div> | |
</template> | |
<style scoped> | |
.modal-mask { | |
position: fixed; | |
z-index: 9998; | |
top: 0; | |
left: 0; | |
width: 100%; | |
height: 100%; | |
background-color: rgba(255, 255, 255, .8); | |
display: block; | |
transition: opacity .3s ease; | |
overflow: auto; | |
padding-top: 100px; | |
} | |
.modal-wrapper { | |
display: block; | |
vertical-align: middle; | |
} | |
.modal-container { | |
width: 500px; | |
margin: 0px auto; | |
padding: 0; | |
background-color: #fff; | |
border-radius: 2px; | |
box-shadow: 0 2px 8px rgba(0, 0, 0, .2); | |
transition: all .3s ease; | |
} | |
</style> | |
<script> | |
export default { | |
name: 'Modal', | |
watch: { | |
show (show) { | |
if (show) { | |
document.body.parentElement.classList.add('noscroll'); | |
} | |
else { | |
document.body.parentElement.classList.remove('noscroll'); | |
} | |
} | |
}, | |
props: { | |
show: { | |
type: Boolean | |
}, | |
title: { | |
type: String | |
}, | |
requestClose: { | |
type: Function | |
}, | |
width: { | |
type: String | |
} | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A few small changes, mainly actually using the title, and passing
requestClose
into the slot