Skip to content

Commit cf2eacf

Browse files
committed
64
1 parent 7bc3e11 commit cf2eacf

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

public/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1414
</noscript>
1515
<div id="app"></div>
16+
<div id="modal"></div>
1617
<!-- built files will be auto injected -->
1718
</body>
1819
</html>

src/components/Modal.vue

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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">&times;</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>

src/components/TodoList.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,28 @@
2424
<div>
2525
<button
2626
class="btn btn-danger btn-sm"
27-
@click.stop="deleteTodo(index)"
27+
@click.stop="openModal(todo.id)"
2828
>
2929
Delete
3030
</button>
3131
</div>
3232
</div>
3333
</div>
34+
<Modal
35+
v-if="showModal"
36+
@close="closeModal"
37+
/>
3438
</template>
3539

3640
<script>
3741
import { useRouter } from 'vue-router';
42+
import Modal from '@/components/Modal.vue';
43+
import { ref } from 'vue';
3844
3945
export default {
46+
components: {
47+
Modal
48+
},
4049
props: {
4150
todos: {
4251
type: Array,
@@ -46,9 +55,21 @@ export default {
4655
emits: ['toggle-todo', 'delete-todo'],
4756
setup(props, { emit }) {
4857
const router = useRouter();
58+
const showModal = ref(false);
59+
const todoDeleteId = ref(null);
4960
const toggleTodo = (index, event) => {
5061
emit('toggle-todo', index, event.target.checked);
5162
};
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+
};
5273
5374
const deleteTodo = (index) => {
5475
emit('delete-todo', index);
@@ -69,6 +90,9 @@ export default {
6990
toggleTodo,
7091
deleteTodo,
7192
moveToPage,
93+
showModal,
94+
openModal,
95+
closeModal,
7296
};
7397
}
7498
}

0 commit comments

Comments
 (0)