In Vue, I'm inserting a value in a 2d array input field and calculating it per row, but the total value that is being returned only calculates the first row, and when I display, the computed value is all the same.
How can i calculate the inputted value so that the value will compute it per row and not just the first value?
<button @click="addFind">add</button>
<tr v-for="(classlist,index) in classlists" :key="'lab'+ classlist.id">
<td>{{index +1}}</td>
<td>{{classlist.student}}</td>
<td v-for="(lab, i) in labs">
<input v-model="lab.value[index]" />
</td>
</tr>
labs: [],
classlists: [
{ "student": "S1","id": 1 },
{ "student": "S2","id": 2 },
{ "student": "S3","id": 3 },
{ "student": "S3","id": 4 },
],
},
methods: {
addFind: function () {
this.labs.push({ value: [] });
}
},
computed: {
studentTotalScores: function() {
return this.labStudentScores.reduce(
(acc, item) => acc + parseInt(item.value),
0
);
}
}
what i need:
NAME | VALUE1 | VALUE2 | TOTAL name1 | 1 | 1 | 2 name2 | 2 | 3 | 5 name3 | | | 0
BUT THE OUTPUT:jsfiddle
NAME | VALUE1 | VALUE2 | TOTAL name1 | 1 | 1 | 2 name2 | 2 | 3 | 2 name3 | | | 2