Recently, I tested out a to-do-list application built in Vue that has a checkbox feature to mark completed items. I'm looking for a way to access the current instance from the checkbox event. Here's what I've accomplished so far:
myObject = new Vue({
el: '#app',
data: {
todos: [{
id: 1,
title: 'Learn HTML',
completed: true
},
{
id: 2,
title: 'Learn CSS',
completed: false
}
]
},
methods: {
markComplete() {
debugger
this.completed = !this.completed;
}
}
})
.is-complete {
text-decoration: line-through;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<ul>
<li v-for="(item,key) in todos" v-bind:class="{'is-complete':item.completed}">
<input type="checkbox" v-on:change="markComplete" :checked="item.completed"> {{ item.title }}
</li>
</ul>
</div>