在Vue中,我在2d数组输入字段中插入一个值并按行计算它,但是返回的总值仅计算第一行,而当我显示时,计算出的值都是相同的。
如何计算输入的值,以便该值将对每行进行计算,而不仅仅是第一个值?
这就是我得到的: 价值的示例图像
NAME | VALUE1 | VALUE2 | TOTAL
name1 | 1 | 1 | 2
name2 | 2 | 3 | 2
name3 | | | 2
脚本
data() {
return {
form: new Form({
labStudentScores: [],
})
};
},
computed: {
studentTotalScore: function() {
return this.form.labStudentScores.reduce(
(acc, item) => acc + parseInt(item.value),
0
);
},
methods: {
addScore: function() {
this.form.labStudentScores.push({ value: [] });
}
}
模板
score(+)
//classlists is comming from http request
{{index +1}}{{classlist.student}}
{{studentTotalScore}}