Created
July 28, 2017 19:50
-
-
Save luanlmd/af7ccaffdcd3694511429d8557bb284f to your computer and use it in GitHub Desktop.
VueJS simplest todo ever
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <title>VueJS simplest todo ever</title> | |
| <script src="https://unpkg.com/vue"></script> | |
| </head> | |
| <body> | |
| <div id="app"> | |
| <ul> | |
| <li v-for="(item, index) in todos" :id="'item-'+index"> | |
| {{ item }} <button @click="remove(index)">x</button> | |
| </li> | |
| </ul> | |
| <input type="text" v-model="todo" placeholder="todo" /> | |
| <button @click="add">add</button> | |
| </div> | |
| </body> | |
| <script> | |
| new Vue({ | |
| el: '#app', | |
| data: { | |
| todos : [], | |
| todo: "" | |
| }, | |
| methods: | |
| { | |
| add: function() { | |
| this.todos.push(this.todo) | |
| this.todo = '' | |
| }, | |
| remove: function(index) { | |
| this.todos.splice(index, 1) | |
| } | |
| }, | |
| watch: { | |
| todos: function(){ | |
| localStorage.todos = JSON.stringify(this.todos) | |
| } | |
| }, | |
| mounted: function() { | |
| this.todos = JSON.parse(localStorage.todos) || [] | |
| } | |
| }); | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment