Skip to content

Commit 37a7e28

Browse files
committed
本地存储完成
1 parent c3e6101 commit 37a7e28

File tree

3 files changed

+64
-59
lines changed

3 files changed

+64
-59
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DS_Store

vuejs入门基础/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/
Lines changed: 62 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,82 @@
11
<template>
22
<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>
1010
</div>
1111
</template>
1212

1313
<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'
1522
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+
};
2924
},
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
4031
}
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+
}
4145
}
42-
}
46+
}
4347
</script>
4448

4549
<style>
46-
.finished {
50+
.finished {
4751
text-decoration: underline;
48-
}
49-
52+
}
5053
51-
html {
52-
height: 100%;
53-
}
54+
html {
55+
height: 100%;
56+
}
5457
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+
}
6164
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+
}
6972
70-
#app a {
71-
color: #42b983;
72-
text-decoration: none;
73-
}
73+
#app a {
74+
color: #42b983;
75+
text-decoration: none;
76+
}
7477
75-
.logo {
76-
width: 100px;
77-
height: 100px
78-
}
78+
.logo {
79+
width: 100px;
80+
height: 100px
81+
}
7982
</style>

0 commit comments

Comments
 (0)