Created
May 29, 2020 09:54
-
-
Save TheBojda/669c50920340067d74d9c3ef8608a8d3 to your computer and use it in GitHub Desktop.
TODO component in Vue.js
This file contains 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
<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