Skip to content

Commit c1d8ccb

Browse files
committed
add move transitions to todomvc example
1 parent 210a3a2 commit c1d8ccb

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

examples/todomvc/index.html

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,25 @@
44
<meta charset="utf-8">
55
<title>Vue.js • TodoMVC</title>
66
<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
7-
<style> [v-cloak] { display: none; } </style>
7+
<style>
8+
[v-cloak] {
9+
display: none;
10+
}
11+
.todo-list {
12+
position: relative;
13+
overflow: hidden;
14+
}
15+
.todo {
16+
height: 60px;
17+
}
18+
.todo-move, .todo-enter-active, .todo-leave-active {
19+
transition: all .25s cubic-bezier(.55,0,.1,1);
20+
}
21+
.todo-enter, .todo-leave-active {
22+
opacity: 0;
23+
height: 0;
24+
}
25+
</style>
826
</head>
927
<body>
1028
<section class="todoapp">
@@ -18,13 +36,14 @@ <h1>todos</h1>
1836
</header>
1937
<section class="main" v-show="todos.length" v-cloak>
2038
<input class="toggle-all" type="checkbox" v-model="allDone">
21-
<ul class="todo-list">
22-
<li class="todo"
23-
v-for="todo in filteredTodos"
24-
:class="{completed: todo.completed, editing: todo == editedTodo}">
39+
<ul class="todo-list" is="transition-group" name="todo">
40+
<li v-for="todo in filteredTodos"
41+
class="todo"
42+
:key="todo.id"
43+
:class="{ completed: todo.completed, editing: todo == editedTodo }">
2544
<div class="view">
2645
<input class="toggle" type="checkbox" v-model="todo.completed">
27-
<label @dblclick="editTodo(todo)">{{todo.title}}</label>
46+
<label @dblclick="editTodo(todo)">{{ todo.title }}</label>
2847
<button class="destroy" @click="removeTodo(todo)"></button>
2948
</div>
3049
<input class="edit" type="text"
@@ -41,9 +60,9 @@ <h1>todos</h1>
4160
<strong>{{ remaining }}</strong> {{ remaining | pluralize }} left
4261
</span>
4362
<ul class="filters">
44-
<li><a href="#/all" :class="{selected: visibility == 'all'}">All</a></li>
45-
<li><a href="#/active" :class="{selected: visibility == 'active'}">Active</a></li>
46-
<li><a href="#/completed" :class="{selected: visibility == 'completed'}">Completed</a></li>
63+
<li><a href="#/all" :class="{ selected: visibility == 'all' }">All</a></li>
64+
<li><a href="#/active" :class="{ selected: visibility == 'active' }">Active</a></li>
65+
<li><a href="#/completed" :class="{ selected: visibility == 'completed' }">Completed</a></li>
4766
</ul>
4867
<button class="clear-completed" @click="removeCompleted" v-show="todos.length > remaining">
4968
Clear completed

examples/todomvc/js/app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@
7878
if (!value) {
7979
return;
8080
}
81-
this.todos.push({ title: value, completed: false });
81+
this.todos.push({
82+
id: todoStorage.uid++,
83+
title: value,
84+
completed: false
85+
});
8286
this.newTodo = '';
8387
},
8488

examples/todomvc/js/store.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44

55
'use strict';
66

7-
var STORAGE_KEY = 'todos-vuejs';
7+
var STORAGE_KEY = 'todos-vuejs-2.0';
88

99
exports.todoStorage = {
1010
fetch: function () {
11-
return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
11+
var todos = JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
12+
todos.forEach(function (todo, index) {
13+
todo.id = index
14+
});
15+
exports.todoStorage.uid = todos.length;
16+
return todos;
1217
},
1318
save: function (todos) {
1419
localStorage.setItem(STORAGE_KEY, JSON.stringify(todos));

0 commit comments

Comments
 (0)