File tree Expand file tree Collapse file tree 3 files changed +78
-1
lines changed Expand file tree Collapse file tree 3 files changed +78
-1
lines changed Original file line number Diff line number Diff line change 13
13
< strong > We're sorry but < %= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</ strong >
14
14
</ noscript >
15
15
< div id ="app "> </ div >
16
+ < div id ="modal "> </ div >
16
17
<!-- built files will be auto injected -->
17
18
</ body >
18
19
</ html >
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" modal-wrapper" >
3
+ <div class =" modal-dialog" >
4
+ <div class =" modal-content" >
5
+ <div class =" modal-header" >
6
+ <h5 class =" modal-title" id =" exampleModalLabel" >Modal title</h5 >
7
+ <button type =" button" class =" close" data-dismiss =" modal" aria-label =" Close" >
8
+ <span @click =" onClose" >× ; </span >
9
+ </button >
10
+ </div >
11
+ <div class =" modal-body" >
12
+ ...
13
+ </div >
14
+ <div class =" modal-footer" >
15
+ <button
16
+ type =" button"
17
+ class =" btn btn-secondary"
18
+ @click =" onClose"
19
+ >
20
+ Close
21
+ </button >
22
+ <button type =" button" class =" btn btn-primary" >Save changes</button >
23
+ </div >
24
+ </div >
25
+ </div >
26
+ </div >
27
+ </template >
28
+
29
+ <script >
30
+ export default {
31
+ setup (props , { emit }) {
32
+ const onClose = () => {
33
+ emit (' close' );
34
+ }
35
+ return {
36
+ onClose
37
+ }
38
+ }
39
+ }
40
+ </script >
41
+
42
+ <style scoped>
43
+ .modal-wrapper {
44
+ position : fixed ;
45
+ z-index : 100 ;
46
+ top : 0 ;
47
+ left : 0 ;
48
+ width : 100% ;
49
+ height : 100% ;
50
+ background-color : rgba (0 , 0 , 0 , 0.5 );
51
+ }
52
+ </style >
Original file line number Diff line number Diff line change 24
24
<div >
25
25
<button
26
26
class =" btn btn-danger btn-sm"
27
- @click.stop =" deleteTodo(index )"
27
+ @click.stop =" openModal(todo.id )"
28
28
>
29
29
Delete
30
30
</button >
31
31
</div >
32
32
</div >
33
33
</div >
34
+ <Modal
35
+ v-if =" showModal"
36
+ @close =" closeModal"
37
+ />
34
38
</template >
35
39
36
40
<script >
37
41
import { useRouter } from ' vue-router' ;
42
+ import Modal from ' @/components/Modal.vue' ;
43
+ import { ref } from ' vue' ;
38
44
39
45
export default {
46
+ components: {
47
+ Modal
48
+ },
40
49
props: {
41
50
todos: {
42
51
type: Array ,
@@ -46,9 +55,21 @@ export default {
46
55
emits: [' toggle-todo' , ' delete-todo' ],
47
56
setup (props , { emit }) {
48
57
const router = useRouter ();
58
+ const showModal = ref (false );
59
+ const todoDeleteId = ref (null );
49
60
const toggleTodo = (index , event ) => {
50
61
emit (' toggle-todo' , index, event .target .checked );
51
62
};
63
+
64
+ const openModal = (id ) => {
65
+ todoDeleteId .value = id;
66
+ showModal .value = true ;
67
+ };
68
+
69
+ const closeModal = () => {
70
+ todoDeleteId .value = null ;
71
+ showModal .value = false ;
72
+ };
52
73
53
74
const deleteTodo = (index ) => {
54
75
emit (' delete-todo' , index);
@@ -69,6 +90,9 @@ export default {
69
90
toggleTodo,
70
91
deleteTodo,
71
92
moveToPage,
93
+ showModal,
94
+ openModal,
95
+ closeModal,
72
96
};
73
97
}
74
98
}
You can’t perform that action at this time.
0 commit comments