vue报错:was assigned to but it has no setter

报错: Computed property "totalScore" was assigned to but it has no setter

 computed: {
    totalScore() {
      const total = this.model.paperPool.map((item) => { return item.num * item.sco}).reduce((pre,cur) => { return pre+cur; });
      console.log(total + this.model.offlineTotalScore)
      return total + this.model.offlineTotalScore;
    },
  },
阅读 18.1k
2 个回答

这个错的意思就是,如果要修改该值,你需要添加set函数。格式如下:

computed:{
    totalScore:{
        get(){
           const total = this.model.paperPool.map((item) => { return item.num * item.sco}).reduce((pre,cur) => { return pre+cur; });
           //在data选项中定义一个变量来接收这个相加的值
           this.totalScore = total + this.model.offlineTotalScore;
           return this.totalScore;
        },
        set(newVal){
            this.totalScore  = newVal;
        }
    }
}
推荐问题
宣传栏