Skip to content

Commit 64dfd0e

Browse files
committed
73
1 parent 43dcd9d commit 64dfd0e

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

db.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@
4444
"subject": "12",
4545
"completed": true,
4646
"id": 15
47+
},
48+
{
49+
"subject": "asdf",
50+
"completed": false,
51+
"body": "adsf",
52+
"id": 16
53+
},
54+
{
55+
"subject": "asdf",
56+
"completed": false,
57+
"body": "asdf",
58+
"id": 17
4759
}
4860
]
4961
}

src/axios.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import axios from 'axios';
2+
3+
export default axios.create({
4+
baseURL: 'http://localhost:3000/'
5+
});

src/components/TodoForm.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
<script>
6464
import { useRoute, useRouter } from 'vue-router';
65-
import axios from 'axios';
65+
import axios from '@/axios';
6666
import { ref, computed } from 'vue';
6767
import _ from 'lodash';
6868
import Toast from '@/components/Toast.vue';
@@ -104,9 +104,7 @@ export default {
104104
const getTodo = async () => {
105105
loading.value = true;
106106
try {
107-
const res = await axios.get(`
108-
http://localhost:3000/todos/${todoId}
109-
`);
107+
const res = await axios.get(`todos/${todoId}`);
110108
111109
todo.value = { ...res.data };
112110
originalTodo.value = { ...res.data };
@@ -152,14 +150,10 @@ export default {
152150
body: todo.value.body,
153151
};
154152
if (props.editing) {
155-
res = await axios.put(`
156-
http://localhost:3000/todos/${todoId}
157-
`, data);
153+
res = await axios.put(`todos/${todoId}`, data);
158154
originalTodo.value = {...res.data};
159155
} else {
160-
res = await axios.post(`
161-
http://localhost:3000/todos
162-
`, data);
156+
res = await axios.post('todos', data);
163157
todo.value.subject = '';
164158
todo.value.body = '';
165159
}

src/pages/todos/index.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<script>
6060
import { ref, computed, watch } from 'vue';
6161
import TodoList from '@/components/TodoList.vue';
62-
import axios from 'axios';
62+
import axios from '@/axios';
6363
import Toast from '@/components/Toast.vue';
6464
import { useToast } from '@/composables/toast';
6565
import {useRouter} from 'vue-router';
@@ -92,7 +92,7 @@ export default {
9292
currentPage.value = page;
9393
try {
9494
const res = await axios.get(
95-
`http://localhost:3000/todos?_sort=id&_order=desc&subject_like=${searchText.value}&_page=${page}&_limit=${limit}`
95+
`todos?_sort=id&_order=desc&subject_like=${searchText.value}&_page=${page}&_limit=${limit}`
9696
);
9797
numberOfTodos.value = res.headers['x-total-count'];
9898
todos.value = res.data;
@@ -109,7 +109,7 @@ export default {
109109
// 데이터베이스 투두를 저장
110110
error.value = '';
111111
try {
112-
await axios.post('http://localhost:3000/todos', {
112+
await axios.post('todos', {
113113
subject: todo.subject,
114114
completed: todo.completed,
115115
});
@@ -126,7 +126,7 @@ export default {
126126
error.value = '';
127127
128128
try {
129-
await axios.delete('http://localhost:3000/todos/' + id);
129+
await axios.delete('todos/' + id);
130130
131131
getTodos(1);
132132
} catch (err) {
@@ -140,7 +140,7 @@ export default {
140140
error.value = '';
141141
const id = todos.value[index].id;
142142
try {
143-
await axios.patch('http://localhost:3000/todos/' + id, {
143+
await axios.patch('todos/' + id, {
144144
completed: checked
145145
});
146146

0 commit comments

Comments
 (0)