Skip to content

Commit bedfacf

Browse files
committed
add:vue3 useScroll
1 parent 150a0c8 commit bedfacf

File tree

14 files changed

+954
-104
lines changed

14 files changed

+954
-104
lines changed

todo-vue2/src/App.vue

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,70 @@
11
<template>
2-
<div class="app">
3-
<input type="text" v-model="newTodo" @keyup.enter="addTodo" />
4-
<div>
5-
<input type="checkbox" v-model="allDone" /> Select All
6-
<ul>
7-
<li
8-
v-for="todo in todos"
9-
:key="todo.id"
10-
:class="{completed: todo.completed, editing: todo == editedTodo}"
11-
>
12-
<div class="view">
13-
<input type="checkbox" v-model="todo.completed" />
14-
<label @dblclick="editTodo(todo)">{{todo.title}}</label>
15-
<button @click="removeTodo(todo)">X</button>
16-
</div>
17-
<input
18-
class="edit"
19-
type="text"
20-
v-model="todo.title"
21-
v-todo-focus="todo == editedTodo"
22-
@blur="doneEdit(todo)"
23-
@keyup.enter="doneEdit(todo)"
24-
@keyup.esc="cancelEdit(todo)"
25-
/>
26-
</li>
27-
</ul>
28-
<div>
29-
<span>
30-
<strong v-text="remaining"></strong>
31-
{{remaining}} left
2+
<section class="todoapp">
3+
<header class="header">
4+
<h1>Vue2 todos</h1>
5+
<input class="new-todo"
6+
placeholder="What needs to be done?"
7+
v-model="newTodo"
8+
@keyup.enter="addTodo">
9+
</header>
10+
<section class="main" v-show="todos.length" v-cloak>
11+
<input class="toggle-all" type="checkbox" v-model="allDone">
12+
<ul class="todo-list">
13+
<li v-for="todo in todos"
14+
class="todo"
15+
:key="todo.id"
16+
:class="{ completed: todo.completed, editing: todo == editedTodo }">
17+
<div class="view">
18+
<input class="toggle" type="checkbox" v-model="todo.completed">
19+
<label @dblclick="editTodo(todo)">{{ todo.title }}</label>
20+
<button class="destroy" @click="removeTodo(todo)"></button>
21+
</div>
22+
<input class="edit" type="text"
23+
v-model="todo.title"
24+
v-todo-focus="todo == editedTodo"
25+
@blur="doneEdit(todo)"
26+
@keyup.enter="doneEdit(todo)"
27+
@keyup.esc="cancelEdit(todo)">
28+
</li>
29+
</ul>
30+
</section>
31+
<footer class="footer" v-show="todos.length" v-cloak>
32+
<span class="todo-count">
33+
<strong>{{ remaining }}</strong> left
3234
</span>
33-
<button @click="removeCompleted" v-show="todos.length > remaining">Clear completed</button>
34-
</div>
35-
</div>
36-
</div>
35+
<button class="clear-completed" @click="removeCompleted" v-show="todos.length > remaining">
36+
Clear completed
37+
</button>
38+
</footer>
39+
</section>
40+
3741
</template>
3842

3943
<script>
44+
45+
import storage from './local'
46+
4047
export default {
4148
data() {
4249
return {
43-
todos: [
44-
{
45-
id: "1",
46-
title: "吃饭",
47-
completed: false
48-
},
49-
{
50-
id: "2",
51-
title: "睡觉",
52-
completed: false
53-
}
54-
],
50+
todos:storage.get(),
51+
// todos: [
52+
// {
53+
// id: "1",
54+
// title: "吃饭",
55+
// completed: false
56+
// },
57+
// {
58+
// id: "2",
59+
// title: "睡觉",
60+
// completed: false
61+
// }
62+
// ],
5563
newTodo: "",
5664
editedTodo: null
5765
};
5866
},
5967
60-
// computed properties
61-
// http://vuejs.org/guide/computed.html
6268
computed: {
6369
remaining: function() {
6470
return this.todos.filter(todo => !todo.completed).length;
@@ -89,16 +95,21 @@ export default {
8995
completed: false
9096
});
9197
this.newTodo = "";
98+
storage.set(this.todos)
9299
},
93100
94101
removeTodo: function(todo) {
95102
var index = this.todos.indexOf(todo);
96103
this.todos.splice(index, 1);
104+
storage.set(this.todos)
105+
97106
},
98107
99108
editTodo: function(todo) {
100109
this.beforeEditCache = todo.title;
101110
this.editedTodo = todo;
111+
storage.set(this.todos)
112+
102113
},
103114
104115
doneEdit: function(todo) {
@@ -110,6 +121,8 @@ export default {
110121
if (!todo.title) {
111122
this.removeTodo(todo);
112123
}
124+
storage.set(this.todos)
125+
113126
},
114127
115128
cancelEdit: function(todo) {
@@ -119,6 +132,8 @@ export default {
119132
120133
removeCompleted: function() {
121134
this.todos = this.todos.filter(todo => todo.completed);
135+
storage.set(this.todos)
136+
122137
}
123138
},
124139

0 commit comments

Comments
 (0)