Skip to content

Instantly share code, notes, and snippets.

@TheBojda
Created May 29, 2020 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBojda/dd88a7f689429261dffd746823337249 to your computer and use it in GitHub Desktop.
Save TheBojda/dd88a7f689429261dffd746823337249 to your computer and use it in GitHub Desktop.
Simple Vue.js TODO app
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue.js TODO Example</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<table>
<tr v-for="(todo, idx) in todos">
<td>{{todo}}</td>
<td><button @click="removeItem(idx)">Done</button></td>
</tr>
<tr>
<td><input type="text" placeholder="TODO item" v-model="todoText" /></td>
<td><button @click="addItem">Add</button></td>
</tr>
</table>
</div>
<script>
new Vue({
el: '#app',
data: {
todoText: '',
todos: []
},
methods: {
addItem() {
this.todos.push(this.todoText);
this.todoText = '';
},
removeItem(idx) {
this.todos.splice(idx, 1);
}
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment