Vue.js Vuejs“;评估过程中的错误“;计算属性
我有一个计算属性,它是Vue.js Vuejs“;评估过程中的错误“;计算属性,vue.js,push,computed-properties,Vue.js,Push,Computed Properties,我有一个计算属性,它是studScore和scores,其中 studScore正在计算我使用push()动态插入的所有插入值。而分数正在计算来自数据库的数据 //DATA from DB props:['students','index'] activities:[ {"id":174,"activity_title":"1","schedule_id":1, "scores": [
studScore
和scores
,其中studScore
正在计算我使用push()
动态插入的所有插入值。而分数
正在计算来自数据库的数据
//DATA from DB
props:['students','index']
activities:[
{"id":174,"activity_title":"1","schedule_id":1,
"scores":
[
{"id":495,"scores":"3","student_id":1,"activity_id":174,},
{"id":496,"scores":"4","student_id":2,"activity_id":174,},
{"id":497,"scores":"5","student_id":3,"activity_id":174}]}
]
//i use this push to insert new input template so ican insert new data
this.activities.push({ activity_title: [], scores: [], id: null, });
//模板
当我试图在
push()
启动时插入新的input
时,我的scores
函数scores:“(评估期间出错)。我得到这个错误是因为它;it’我的模板中第三个输入
,但我不知道如何解决这个问题。乍一看,我觉得好像您将v-for索引属性命名为i,但您尝试将其作为索引访问。
computed: {
//this function compute all newly added data in my input template
studScore: function() {
return this.students.map((c, index) => {
return this.activities.reduce((acc, item) => {
const value = parseFloat(item.scores[index], 10) || 0;
return acc + value;
}, 0);
});
},
//this compute the the total scores coming from DB
scores: function() {
return this.students.map((c, index) => {
return this.activities.reduce((acc, item) => {
const value = parseFloat(item.scores[index].scores, 10) || 0;
return acc + value;
}, 0);
});
},
},
//template
<td class v-for="(quiz,i) in activities" :key="i">
<input v-if="!quiz.scores[index]" v-model="quiz.scores[index]" />
<input v-else-if="quiz.scores[index].scores" v-model="quiz.scores[index].scores" />
<input v-else v-model="quiz.scores[index]" autocomplete="off" />
</td>