진스
slot을 이용한 modal(모달) 사용 feat) transition 본문
728x90
codesandbox
Input.vue (상위 컴포넌트)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<template>
<div>
<div class="md-layout" style="margin: 0.5rem; color: #fff !important">
<div class="md-layout-item md-size-90">
<label>빈칸 엔터면? </label>
<input v-model="doItem" @keyup.enter="addTodo"></input>
</div>
<div class="md-layout-item md-size-10" @click="addTodo">
<i class="fas fa-plus-circle addBtn"></i>
</div>
<Modal v-if="showModal" @close="showModal = false">
<h3 slot="header">
알림!
<i class="fas fa-times closeModalBtn" @click="showModal = false"></i>
</h3>
<div slot="body">할일을 입력하세요.</div>
</Modal>
</div>
</div>
</template>
<script>
import Modal from "./components/Modal";
export default {
components: {
Modal,
},
data: function () {
return {
doItem: "",
showModal: false,
};
},
methods: {
addTodo() {
if (this.doItem) {
// this.$emit('이벤트이름', 인자1, 인자2);
this.$emit("addOne", this.doItem);
this.clearInput();
} else {
this.showModal = !this.showModal;
}
},
clearInput() {
this.doItem = "";
},
},
};
</script>
<style>
.md-field,
.md-focused,
.md-input,
.md-textarea,
label {
background: #365fd9 !important;
border-style: none;
border-radius: 5px;
margin: 0 0 5px 0 !important;
color: #fff !important;
-webkit-text-fill-color: #ddd !important;
}
.addBtn {
vertical-align: middle;
margin-top: 12px;
font-size: 24px;
cursor: pointer;
}
.closeModalBtn {
color: #42b983;
}
</style>
|
cs |
Modal.vue (하위컴포넌트)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
<template>
<transition name="modal">
<div class="modal-mask">
<div class="modal-wrapper">
<div class="modal-container">
<div class="modal-header">
<slot name="header"> default header </slot>
</div>
<div class="modal-body">
<slot name="body"> default body </slot>
</div>
<div class="modal-footer">
<slot name="footer">
default footer
<button class="modal-default-button" @click="$emit('close')">
close
</button>
</slot>
</div>
</div>
</div>
</div>
</transition>
</template>
<script>
export default {};
</script>
<style>
.modal-mask {
position: fixed;
z-index: 9998;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: table;
transition: opacity 0.3s ease;
}
.modal-wrapper {
display: table-cell;
vertical-align: middle;
}
.modal-container {
width: 300px;
margin: 0px auto;
padding: 20px 30px;
background-color: #fff;
border-radius: 2px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
transition: all 0.3s ease;
font-family: Helvetica, Arial, sans-serif;
}
.modal-header h3 {
margin-top: 0;
color: #42b983;
}
.modal-body {
margin: 20px 0;
}
.modal-default-button {
float: right;
}
.modal-enter {
opacity: 0;
}
.modal-leave-active {
opacity: 0;
}
.modal-enter .modal-container,
.modal-leave-active .modal-container {
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.modal-body,
.modal {
color: #666 !important;
}
</style>
|
cs |
728x90
'Vue' 카테고리의 다른 글
eslint와prettier 설정 (0) | 2021.05.10 |
---|---|
video 태그 삽입 (0) | 2021.05.06 |
vue에서 background-image 적용하기 (1) | 2021.05.03 |
카카오 Rest api 이용해보기 (0) | 2021.05.01 |
vuex 새로고침시 상태 초기화 방지 (0) | 2021.04.30 |
Comments