Skip to content

Commit 0a2c31e

Browse files
committed
Step 9 - Persist
1 parent eab0467 commit 0a2c31e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/app.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
<script>
2929
30+
var STORE_KEY = "todos";
31+
3032
var filters = {
3133
all: (todos) => todos,
3234
active: (todos) => todos.filter(todo => !todo.completed),
@@ -35,11 +37,18 @@ var filters = {
3537
3638
export default {
3739
data: {
38-
todos: [],
40+
todos: JSON.parse(localStorage.getItem(STORE_KEY) || '[]'),
3941
input: '',
4042
filter: 'all'
4143
},
4244
45+
watch: {
46+
todos: {
47+
handler: (todos) => localStorage.setItem(STORE_KEY, JSON.stringify(todos)),
48+
deep: true
49+
}
50+
},
51+
4352
computed: {
4453
remaining() { return filters.active(this.todos).length; },
4554
filtered() { return filters[this.filter](this.todos); }

0 commit comments

Comments
 (0)