File tree Expand file tree Collapse file tree 2 files changed +51
-9
lines changed Expand file tree Collapse file tree 2 files changed +51
-9
lines changed Original file line number Diff line number Diff line change 64
64
"subject" : " new todo222" ,
65
65
"completed" : true ,
66
66
"id" : 21
67
+ },
68
+ {
69
+ "subject" : " buy milk" ,
70
+ "completed" : false ,
71
+ "body" : " go to supermarket and buy milk" ,
72
+ "id" : 22
73
+ },
74
+ {
75
+ "subject" : " buy milk" ,
76
+ "completed" : false ,
77
+ "body" : " buy milk at supermarket" ,
78
+ "id" : 23
79
+ },
80
+ {
81
+ "subject" : " asdfasdf" ,
82
+ "completed" : false ,
83
+ "body" : " asdfasdf" ,
84
+ "id" : 24
85
+ },
86
+ {
87
+ "subject" : " asdf" ,
88
+ "completed" : false ,
89
+ "body" : " asdf" ,
90
+ "id" : 25
91
+ },
92
+ {
93
+ "subject" : " dgdsfg" ,
94
+ "completed" : false ,
95
+ "body" : " dfghdfgh" ,
96
+ "id" : 26
67
97
}
68
98
]
69
99
}
Original file line number Diff line number Diff line change 45
45
class =" btn btn-primary"
46
46
:disabled =" !todoUpdated"
47
47
>
48
- Save
48
+ {{ editing ? 'Update' : 'Create'}}
49
49
</button >
50
50
<button
51
51
class =" btn btn-outline-dark ml-2"
@@ -136,15 +136,27 @@ export default {
136
136
137
137
const onSave = async () => {
138
138
try {
139
- const res = await axios .put (`
140
- http://localhost:3000/todos/${ todoId}
141
- ` , {
139
+ let res;
140
+ const data = {
142
141
subject: todo .value .subject ,
143
- completed: todo .value .completed
144
- });
145
-
146
- originalTodo .value = {... res .data };
147
- triggerToast (' Successfully saved!' );
142
+ completed: todo .value .completed ,
143
+ body: todo .value .body ,
144
+ };
145
+ if (props .editing ) {
146
+ res = await axios .put (`
147
+ http://localhost:3000/todos/${ todoId}
148
+ ` , data);
149
+ originalTodo .value = {... res .data };
150
+ } else {
151
+ res = await axios .post (`
152
+ http://localhost:3000/todos
153
+ ` , data);
154
+ todo .value .subject = ' ' ;
155
+ todo .value .body = ' ' ;
156
+ }
157
+
158
+ const message = ' Successfully ' + (props .editing ? ' Updated!' : ' Created!' );
159
+ triggerToast (message);
148
160
} catch (error) {
149
161
console .log (error);
150
162
triggerToast (' Something went wrong' , ' danger' )
You can’t perform that action at this time.
0 commit comments