File tree 5 files changed +39
-79
lines changed
5 files changed +39
-79
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
2
<TodoHeader />
3
- <TodoInput />
4
- <TodoList />
5
- <TodoFooter />
3
+ <TodoInput @addTodo = " addTodo " />
4
+ <TodoList :todoItems = " todoItems " @removeTodo = " removeTodo " />
5
+ <TodoFooter @removeAll = " clearAll " />
6
6
</template >
7
7
8
8
<script >
@@ -19,6 +19,33 @@ export default {
19
19
TodoList,
20
20
TodoFooter,
21
21
},
22
+ data () {
23
+ return {
24
+ todoItems: [],
25
+ };
26
+ },
27
+ methods: {
28
+ clearAll () {
29
+ localStorage .clear ();
30
+ this .todoItems = [];
31
+ },
32
+ addTodo (newTodoItem ) {
33
+ localStorage .setItem (newTodoItem, newTodoItem);
34
+ this .todoItems .push (newTodoItem);
35
+ },
36
+ removeTodo (todoItem , index ) {
37
+ localStorage .removeItem (todoItem);
38
+ this .todoItems .splice (index, 1 );
39
+ },
40
+ },
41
+ created () {
42
+ // ๋ทฐ ์ธ์คํด์ค๊ฐ ์์ฑ๋์๋ง์ ๋ทฐ ๋ฐ์ดํฐ์ ์ ๊ทผํ ์ ์๋๋ก created()์์ ๋ก์ปฌ์คํ ๋ฆฌ์ง ๋ฐ์ดํฐ๋ฅผ ๋ทฐ ๋ฐ์ดํฐ๋ก ์ฎ๊น
43
+ if (localStorage .length > 0 ) {
44
+ for (let i = 0 ; i < localStorage .length ; i++ ) {
45
+ this .todoItems .push (localStorage .key (i));
46
+ }
47
+ }
48
+ },
22
49
};
23
50
</script >
24
51
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 8
8
export default {
9
9
methods: {
10
10
clearTodo () {
11
- localStorage . clear ( );
11
+ this . $emit ( " removeAll " );
12
12
},
13
13
},
14
14
};
Original file line number Diff line number Diff line change 4
4
type =" text"
5
5
v-model =" newTodoItem"
6
6
placeholder =" Things I have to do..."
7
- @keyup .enter =" addTodo"
7
+ @keypress .enter =" addTodo"
8
8
/>
9
9
<span class =" addContainer" @click =" addTodo" >
10
10
<i class =" addBtn fas fa-plus" aria-hidden =" true" ></i >
@@ -23,13 +23,17 @@ export default {
23
23
addTodo () {
24
24
if (this .newTodoItem !== " " ) {
25
25
const value = this .newTodoItem && this .newTodoItem .trim ();
26
- localStorage . setItem (value , value);
26
+ this . $emit ( " addTodo " , value);
27
27
this .clearInput ();
28
28
}
29
29
},
30
30
clearInput () {
31
31
this .newTodoItem = " " ;
32
32
},
33
+ removeTodo (todoItem , index ) {
34
+ localStorage .removeItem (todoItem);
35
+ this .todoItems .splice (index, 1 );
36
+ },
33
37
},
34
38
};
35
39
</script >
Original file line number Diff line number Diff line change 18
18
19
19
<script >
20
20
export default {
21
- data () {
22
- return {
23
- todoItems: [],
24
- };
25
- },
26
- created () {
27
- // ๋ทฐ ์ธ์คํด์ค๊ฐ ์์ฑ๋์๋ง์ ๋ทฐ ๋ฐ์ดํฐ์ ์ ๊ทผํ ์ ์๋๋ก created()์์ ๋ก์ปฌ์คํ ๋ฆฌ์ง ๋ฐ์ดํฐ๋ฅผ ๋ทฐ ๋ฐ์ดํฐ๋ก ์ฎ๊น
28
- if (localStorage .length > 0 ) {
29
- for (let i = 0 ; i < localStorage .length ; i++ ) {
30
- this .todoItems .push (localStorage .key (i));
31
- }
32
- }
33
- },
21
+ props: [" todoItems" ],
34
22
methods: {
35
23
removeTodo (todoItem , index ) {
36
- localStorage .removeItem (todoItem);
37
- this .todoItems .splice (index, 1 );
24
+ this .$emit (" removeTodo" , todoItem, index);
38
25
},
39
26
},
40
27
};
You canโt perform that action at this time.
0 commit comments