Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vuejs“;评估过程中的错误“;计算属性_Vue.js_Push_Computed Properties - Fatal编程技术网

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>