|
1 | 1 | <template>
|
2 | 2 | <div id="app">
|
3 |
| - <h1 v-text="title"></h1> |
4 |
| - <input v-model="newItem" v-on:keyup.enter="addNew"> |
5 |
| - <ul> |
6 |
| - <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)"> |
7 |
| - {{item.label}} |
8 |
| - </li> |
9 |
| - </ul> |
| 3 | + <h1 v-text="title"></h1> |
| 4 | + <input v-model="newItem" v-on:keyup.enter="addNew"> |
| 5 | + <ul> |
| 6 | + <li v-for="item in items" v-bind:class="{finished:item.isFinished}" v-on:click="toggleFinish(item)"> |
| 7 | + {{item.label}} |
| 8 | + </li> |
| 9 | + </ul> |
10 | 10 | </div>
|
11 | 11 | </template>
|
12 | 12 |
|
13 | 13 | <script>
|
14 |
| -import Store from './store' |
| 14 | + import Store from './store' |
| 15 | + export default { |
| 16 | + data: function () { |
| 17 | + return { |
| 18 | + title: 'this is a todo list', |
| 19 | + items: Store.fetch(), |
| 20 | + newItem: '', |
| 21 | + liClass: 'thisisliClass' |
15 | 22 |
|
16 |
| -
|
17 |
| -export default { |
18 |
| - data:function(){ |
19 |
| - return { |
20 |
| - title:'this is a todo list', |
21 |
| - items:[ |
22 |
| - {label:'coding',isFinished:false |
23 |
| - },{ |
24 |
| - label:'walking',isFinished:true |
25 |
| - }], |
26 |
| - newItem:'', |
27 |
| - liClass:'thisisliClass' |
28 |
| - }; |
| 23 | + }; |
29 | 24 | },
|
30 |
| - methods:{ |
31 |
| - toggleFinish:function(item){ |
32 |
| - item.isFinished = !item.isFinished; |
33 |
| - }, |
34 |
| - addNew:function(){ |
35 |
| - this.items.push({ |
36 |
| - label:this.newItem, |
37 |
| - isFinished:false, |
38 |
| - }); |
39 |
| - this.newItem = ''; |
| 25 | + watch:{ |
| 26 | + items:{ |
| 27 | + handler:function(items){ |
| 28 | + Store.save(items); |
| 29 | + }, |
| 30 | + deep:true |
40 | 31 | }
|
| 32 | + }, |
| 33 | + methods: { |
| 34 | + toggleFinish: function (item) { |
| 35 | + item.isFinished = !item.isFinished; |
| 36 | +
|
| 37 | + }, |
| 38 | + addNew: function () { |
| 39 | + this.items.push({ |
| 40 | + label: this.newItem, |
| 41 | + isFinished: false, |
| 42 | + }); |
| 43 | + this.newItem = ''; |
| 44 | + } |
41 | 45 | }
|
42 |
| -} |
| 46 | + } |
43 | 47 | </script>
|
44 | 48 |
|
45 | 49 | <style>
|
46 |
| -.finished { |
| 50 | + .finished { |
47 | 51 | text-decoration: underline;
|
48 |
| -} |
49 |
| -
|
| 52 | + } |
50 | 53 |
|
51 |
| -html { |
52 |
| - height: 100%; |
53 |
| -} |
| 54 | + html { |
| 55 | + height: 100%; |
| 56 | + } |
54 | 57 |
|
55 |
| -body { |
56 |
| - display: flex; |
57 |
| - align-items: center; |
58 |
| - justify-content: center; |
59 |
| - height: 100%; |
60 |
| -} |
| 58 | + body { |
| 59 | + display: flex; |
| 60 | + align-items: center; |
| 61 | + justify-content: center; |
| 62 | + height: 100%; |
| 63 | + } |
61 | 64 |
|
62 |
| -#app { |
63 |
| - color: #2c3e50; |
64 |
| - margin-top: -100px; |
65 |
| - max-width: 600px; |
66 |
| - font-family: Source Sans Pro, Helvetica, sans-serif; |
67 |
| - text-align: center; |
68 |
| -} |
| 65 | + #app { |
| 66 | + color: #2c3e50; |
| 67 | + margin-top: -100px; |
| 68 | + max-width: 600px; |
| 69 | + font-family: Source Sans Pro, Helvetica, sans-serif; |
| 70 | + text-align: center; |
| 71 | + } |
69 | 72 |
|
70 |
| -#app a { |
71 |
| - color: #42b983; |
72 |
| - text-decoration: none; |
73 |
| -} |
| 73 | + #app a { |
| 74 | + color: #42b983; |
| 75 | + text-decoration: none; |
| 76 | + } |
74 | 77 |
|
75 |
| -.logo { |
76 |
| - width: 100px; |
77 |
| - height: 100px |
78 |
| -} |
| 78 | + .logo { |
| 79 | + width: 100px; |
| 80 | + height: 100px |
| 81 | + } |
79 | 82 | </style>
|
0 commit comments