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;
        }
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏