Vuex:Computed property "comps" was assigned to but it has no setter.
项目中控制台报错,comps 是vuex里的全局状态:
computed: {
...mapGetters(["comps"])
}
查了半天,发现其他地方对comps进行了重新赋值操作:
this.comps=[];
感谢大米的评论,确实是不能违背vuex的原则,state的改变只能在mutations 和 actions中完成,在 mutations和actions中分别加了changeComps方法:
mutations: {
changeComps(state, paramsObj) {
state.comps = paramsObj.comps;
}
},
actions: {
changeComps({ commit, rootState }, paramsObj) {
commit('changeComps', paramsObj)
}
}
通过dispatch分发就可以了:
this.$store.dispatch("changeComps", {
comps: this.comps,
});
发表评论 (审核通过后显示评论):