Skip to content

Instantly share code, notes, and snippets.

@TheBojda
Created May 29, 2020 09:54
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/669c50920340067d74d9c3ef8608a8d3 to your computer and use it in GitHub Desktop.
Save TheBojda/669c50920340067d74d9c3ef8608a8d3 to your computer and use it in GitHub Desktop.
TODO component in Vue.js
<template>
<table>
<tr v-for="(todo, idx) in todos" :key="idx">
<td class="todo_text">{{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>
</template>
<script>
module.exports = {
data() {
return {
todoText: "",
todos: []
};
},
methods: {
addItem() {
this.todos.push(this.todoText);
this.todoText = "";
},
removeItem(idx) {
this.todos.splice(idx, 1);
}
}
};
</script>
<style>
.todo_text {
font-style: italic;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment