File tree 3 files changed +121
-2
lines changed
3 files changed +121
-2
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,10 @@ export default {
30
30
this .todoItems = [];
31
31
},
32
32
addTodo (newTodoItem ) {
33
- localStorage .setItem (newTodoItem, newTodoItem);
34
- this .todoItems .push (newTodoItem);
33
+ if (newTodoItem !== " " ) {
34
+ localStorage .setItem (newTodoItem, newTodoItem);
35
+ this .todoItems .push (newTodoItem);
36
+ }
35
37
},
36
38
removeTodo (todoItem , index ) {
37
39
localStorage .removeItem (todoItem);
Original file line number Diff line number Diff line change 4
4
type =" text"
5
5
v-model =" newTodoItem"
6
6
placeholder =" Things I have to do..."
7
+ ref =" inputBox"
7
8
@keypress.enter =" addTodo"
8
9
/>
9
10
<span class =" addContainer" @click =" addTodo" >
10
11
<i class =" addBtn fas fa-plus" aria-hidden =" true" ></i >
11
12
</span >
13
+
14
+ <Modal v-if =" showModal" @close =" closeModal" >
15
+ <template v-slot :header >경고</template >
16
+ <template v-slot :footer @click =" closeModal "
17
+ >할 일을 입력하세요.
18
+ <i
19
+ class =" closeModalBtn fas fa-times"
20
+ aria-hidden =" true"
21
+ @click =" closeModal"
22
+ ></i >
23
+ </template >
24
+ </Modal >
12
25
</div >
13
26
</template >
14
27
15
28
<script >
29
+ import Modal from " ./common/Modal.vue" ;
30
+
16
31
export default {
17
32
data () {
18
33
return {
19
34
newTodoItem: " " ,
35
+ showModal: false ,
20
36
};
21
37
},
22
38
methods: {
@@ -25,6 +41,9 @@ export default {
25
41
const value = this .newTodoItem && this .newTodoItem .trim ();
26
42
this .$emit (" addTodo" , value);
27
43
this .clearInput ();
44
+ } else {
45
+ this .showModal = true ;
46
+ this .$refs .inputBox .blur ();
28
47
}
29
48
},
30
49
clearInput () {
@@ -34,6 +53,12 @@ export default {
34
53
localStorage .removeItem (todoItem);
35
54
this .todoItems .splice (index, 1 );
36
55
},
56
+ closeModal () {
57
+ this .showModal = false ;
58
+ },
59
+ },
60
+ components: {
61
+ Modal,
37
62
},
38
63
};
39
64
</script >
Original file line number Diff line number Diff line change
1
+ <template lang="html">
2
+ <transition name =" modal" >
3
+ <div class =" modal-mask" @click =" closeModal" >
4
+ <div class =" modal-wrapper" >
5
+ <div class =" modal-container" >
6
+ <div class =" modal-header" >
7
+ <slot name =" header" >
8
+ <!-- -->
9
+ </slot>
10
+ </div>
11
+
12
+ <div class =" modal-footer" >
13
+ <slot name =" footer" >
14
+ <!-- -->
15
+ </slot>
16
+ </div>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ </transition>
21
+ </template >
22
+
23
+ <script >
24
+ export default {
25
+ methods: {
26
+ closeModal () {
27
+ console .log (" safas" );
28
+ this .$emit (" close" );
29
+ },
30
+ },
31
+ };
32
+ </script >
33
+
34
+ <style >
35
+ .closeModalBtn {
36
+ color : #62acde ;
37
+ }
38
+ .modal-mask {
39
+ position : fixed ;
40
+ z-index : 9998 ;
41
+ top : 0 ;
42
+ left : 0 ;
43
+ width : 100% ;
44
+ height : 100% ;
45
+ background-color : rgba (0 , 0 , 0 , 0.5 );
46
+ display : table ;
47
+ transition : opacity 0.3s ease ;
48
+ }
49
+ .modal-wrapper {
50
+ display : table-cell ;
51
+ vertical-align : middle ;
52
+ }
53
+ .modal-container {
54
+ width : 300px ;
55
+ margin : 0px auto ;
56
+ padding : 20px 30px ;
57
+ background-color : #fff ;
58
+ border-radius : 2px ;
59
+ box-shadow : 0 2px 8px rgba (0 , 0 , 0 , 0.33 );
60
+ transition : all 0.3s ease ;
61
+ font-family : Helvetica , Arial , sans-serif ;
62
+ }
63
+ .modal-header h3 {
64
+ margin-top : 0 ;
65
+ color : #62acde ;
66
+ }
67
+ .modal-body {
68
+ margin : 20px 0 ;
69
+ }
70
+ .modal-default-button {
71
+ float : right ;
72
+ }
73
+ /*
74
+ * The following styles are auto-applied to elements with
75
+ * transition="modal" when their visibility is toggled
76
+ * by Vue.js.
77
+ *
78
+ * You can easily play with the modal transition by editing
79
+ * these styles.
80
+ */
81
+ .modal-enter {
82
+ opacity : 0 ;
83
+ }
84
+ .modal-leave-active {
85
+ opacity : 0 ;
86
+ }
87
+ .modal-enter .modal-container ,
88
+ .modal-leave-active .modal-container {
89
+ -webkit-transform : scale (1.1 );
90
+ transform : scale (1.1 );
91
+ }
92
+ </style >
You can’t perform that action at this time.
0 commit comments