<div id="app">
<modal v-show="toggleModal" @click="closeModal">
<div class="modal-header" slot="header">
<div class="close rotate" @click="closeModal">
<i class="fa-times fa"></i>
</div>
<h3 class="modal-title">Modal Header</h3>
</div>
<div class="modal-body" slot="body">
<h3>Modal Body</h3>
<p>Modal body conent...</p>
</div>
<div class="modal-footer" slot="footer">
<button class="btn" @click="closeModal">关闭</button>
</div>
</modal>
<button class="btn btn-open" @click="showModal">Show Modal</button>
</div>
<template id="modal">
<div class="modal-backdrop">
<div class="modal" @click.stop>
<slot name="header"></slot>
<slot name="body"></slot>
<slot name="footer"></slot>
</div>
</div>
</template>
@import url('https://fonts.googleapis.com/css?family=Lato|Roboto:700');
body {
background-color: #1b1fdc6b;
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAQAAABuBnYAAAAAU0lEQVQIHQXBwRGDIBAAwO2/AMcCDHAcPjIRxjJ8Je1kl1uqUgphsWu6w0sIG6npLpcUBql4e/wsVRKabrkNTacIYbMrwsF06rqUhsnXVKVT+Hj+Ue4rPSONk4kAAAAASUVORK5CYII=);
background-blend-mode: lighten, color-dodge;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
color: #fff;
font-family: 'Lato', sans-serif;
line-height: 1.4;
margin: 1rem;
}
.btn {
display: inline-block;
border: 0;
box-sizing: border-box;
background: #cb4a70;
color: #fff;
font-size: 1.5em;
border-radius: .1em;
line-height: 2em;
padding: 0 1em;
transition: .4s ease-out;
border: 1px solid #cb4a70;
outline: 0;
text-decoration: none;
}
.btn:hover,
.btn:focus {
background: #fff;
color: #cb4a70;
cursor: pointer;
transition: .15s ease-in;
}
.modal-backdrop {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: rgba(0,0,0,.65);
display: flex;
justify-content: center;
align-items: center;
z-index: 999
}
.modal {
min-width: 50vw;
background: #fff;
border-radius: 3px;
box-shadow: 0 0 3px 0px rgba(255, 255, 255, .3);
}
.modal-header {
background: #cb4a70;
color: #fff;
position: relative;
border-radius: 3px 3px 0 0;
padding: 0 2em;
}
.modal-title {
margin: 0;
font-size: 2em;
font-weight: 200;
line-height: 2em;
}
.modal-body {
padding: 2em;
color: #333;
}
.modal-footer {
padding: 1em 2em;
text-align: right;
border-top: 1px solid rgba(0, 0, 0, 0.1);
border-radius: 0 0 3px 3px;
}
.close {
width: 2.5rem;
height: 2.5rem;
position: absolute;
top: -1.2rem;
right: -1.2rem;
transition: .8s ease all;
border: none;
color: #fff;
text-decoration: none;
box-sizing: border-box;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
background: rgba(255, 255, 255, .6);
font-size: 2rem;
}
.close:hover {
transition: .8s ease all;
}
.close .iconfont {
font-size: 2rem;
color: #fff;
}
.rotate {
cursor: pointer;
}
.rotate:hover {
transform: rotate(360deg);
transition: transform 1.0s ease all;
}
View Compiled
Vue.component('modal', {
template: '#modal',
methods: {
close: function (event) {
this.$emit('close');
}
}
})
let app = new Vue({
el: '#app',
data () {
return {
toggleModal: false
}
},
methods: {
showModal: function () {
this.toggleModal = true
},
closeModal: function () {
this.toggleModal = false
}
}
})
View Compiled