Vue
HTML
<div id="app">
<h2>Todos:</h2>
<ol>
<li v-for="todo in todos">
<label>
<input type="checkbox" v-model="todo.checked">
{{ todo.text }} <b v-if="todo.checked">( {{ todo.calc }} )</b>
</label>
</li>
</ol>
{{ calc }}
</div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
}
li {
margin: 8px 0;
}
h2 {
font-weight: bold;
margin-bottom: 15px;
}
del {
color: rgba(0, 0, 0, 0.3);
}
Vue
new Vue({
el: "#app",
data: {
todos: [
{ text: "Learn JavaScript", val: 10, calc: 0 },
{ text: "Learn Vue", val: 20, calc: 0 },
{ text: "Play around in JSFiddle", val: 30, calc: 0 },
{ text: "Build something awesome", val: 40, calc: 0 }
]
},
computed: {
calc() {
var total = 0;
this.todos.forEach(function(item){
if(item.checked === true) {
item.calc = item.val * 2;
total += item.calc;
}
});
return total
}
}
})