Skip to content

Commit 220de47

Browse files
committed
50
1 parent f93c10b commit 220de47

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

db.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
"id": 18
6262
},
6363
{
64-
"subject": "new todo",
64+
"subject": "new todo2",
6565
"completed": true,
6666
"id": 21
6767
}

src/pages/todos/_id.vue

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
<div v-if="loading">
44
Loading..
55
</div>
6-
<form v-else>
6+
<form
7+
v-else
8+
@submit.prevent="onSave"
9+
>
710
<div class="row">
811
<div class="col-6">
912
<div class="form-group">
@@ -55,9 +58,10 @@ export default {
5558
const router = useRouter();
5659
const todo = ref(null);
5760
const loading = ref(true);
61+
const todoId = route.params.id
5862
5963
const getTodo = async () => {
60-
const res = await axios.get('http://localhost:3000/todos/' + route.params.id);
64+
const res = await axios.get(`http://localhost:3000/todos/${todoId}`);
6165
6266
todo.value = res.data;
6367
loading.value = false;
@@ -75,11 +79,21 @@ export default {
7579
7680
getTodo();
7781
82+
const onSave = async () => {
83+
const res = await axios.put(`http://localhost:3000/todos/${todoId}`, {
84+
subject: todo.value.subject,
85+
completed: todo.value.completed
86+
});
87+
88+
console.log(res);
89+
};
90+
7891
return {
7992
todo,
8093
loading,
8194
toggleTodoStatus,
8295
moveToTodoListPage,
96+
onSave,
8397
};
8498
}
8599
}

0 commit comments

Comments
 (0)