data: () => ({
items: [
{ value: 69, title: 'hello, world!!', checked: false },
{ value: 187, title: 'fuck the world', checked: false },
{ value: 666, title: 'fuck everything', checked: false },
],
}),
computed: {
sum() {
return this.items.reduce((acc, n) => acc + n.value * n.checked, 0);
},
checkAll: {
get() {
return this.items.every(n => n.checked);
},
set(val) {
this.items.forEach(n => n.checked = val);
},
},
},
<div>
<label>
<input type="checkbox" v-model="checkAll">
CHECK ALL
</label>
</div>
<div v-for="n in items">
<label>
<input type="checkbox" v-model="n.checked">
{{ n.title }}
</label>
</div>
<div>SUM: {{ sum }}</div>