Permalink
Browse files

vue watchers and localstorage

  • Loading branch information...
amejiarosario committed Aug 14, 2018
1 parent 790b241 commit 579da191f747095c50c6fcb4699a1aa56b825ddc
Showing with 12 additions and 2 deletions.
  1. +12 −2 app.js
14 app.js
@@ -1,8 +1,10 @@
const LOCAL_STORAGE_KEY = 'todo-app-vue';
const todoApp = new Vue({
el: '.todoapp',
data: {
title: 'Todos',
todos: [
todos: JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY)) || [
{ text: 'Learn JavaScript ES6+ goodies', isDone: true },
{ text: 'Learn Vue', isDone: false },
{ text: 'Build something awesome', isDone: false },
@@ -42,5 +44,13 @@ const todoApp = new Vue({
completedTodos() {
return this.todos.filter(t => t.isDone);
}
}
},
watch: {
todos: {
deep: true,
handler(newValue) {
localStorage.setItem(LOCAL_STORAGE_KEY, JSON.stringify(newValue));
}
}
},
});

0 comments on commit 579da19

Please sign in to comment.