-
-
Save fbonetti/5fb6b813340c7a0a6a67efb7dc90666d to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<script src="https://cdn.jsdelivr.net/npm/vue"></script> | |
<style> | |
.completed { | |
text-decoration: line-through | |
} | |
</style> | |
</head> | |
<body> | |
<div id="todo-app"> | |
<ul> | |
<li v-for="(task, index) in tasks" | |
v-bind:class="{ completed: task.completed }" | |
v-on:click="toggleTaskCompleted(index)" | |
> | |
{{ task.name }} | |
</li> | |
</ul> | |
</div> | |
<script> | |
const app = new Vue({ | |
el: '#todo-app', | |
data: { | |
tasks: [ | |
{ name: 'Walk the dog', completed: false }, | |
{ name: 'Pay bills', completed: false }, | |
{ name: 'Make dinner', completed: false }, | |
{ name: 'Code for one hour', completed: false } | |
] | |
}, | |
methods: { | |
toggleTaskCompleted: function (index) { | |
const task = this.tasks[index] | |
task.completed = !task.completed | |
this.$set(this.tasks, index, task) | |
} | |
} | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment